public void TestRemarksElement()
        {
            string expected =
                "<remarks>\r\n"
                + "/// <para>Remarks.</para>\r\n"
                + "/// </remarks>";

            Assert.Equal(expected, XmlSyntaxFactory.RemarksElement("\r\n", XmlSyntaxFactory.ParaElement(XmlSyntaxFactory.Text("Remarks."))).ToFullString());
        }
        private static async Task <Document> GetTransformedDocumentAsync(Document document, Diagnostic diagnostic, CancellationToken cancellationToken)
        {
            SyntaxNode root = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false);

            SyntaxNode enclosingNode = root.FindNode(diagnostic.Location.SourceSpan, findInsideTrivia: true);

            if (!(enclosingNode is XmlNodeSyntax xmlNodeSyntax))
            {
                return(document);
            }

            XmlElementSyntax xmlElementSyntax = xmlNodeSyntax.FirstAncestorOrSelf <XmlElementSyntax>();

            if (xmlElementSyntax == null)
            {
                return(document);
            }

            SyntaxToken startToken = root.FindToken(diagnostic.Location.SourceSpan.Start, findInsideTrivia: true);

            if (!(startToken.Parent is XmlNodeSyntax startNode) || startNode == xmlElementSyntax)
            {
                return(document);
            }

            while (startNode.Parent != xmlElementSyntax)
            {
                startNode = startNode.Parent as XmlNodeSyntax;
                if (startNode == null)
                {
                    return(document);
                }
            }

            SyntaxToken stopToken = root.FindToken(diagnostic.Location.SourceSpan.End - 1, findInsideTrivia: true);

            if (!(stopToken.Parent is XmlNodeSyntax stopNode) || stopNode == xmlElementSyntax)
            {
                return(document);
            }

            while (stopNode.Parent != xmlElementSyntax)
            {
                stopNode = stopNode.Parent as XmlNodeSyntax;
                if (stopNode == null)
                {
                    return(document);
                }
            }

            int startIndex = xmlElementSyntax.Content.IndexOf(startNode);
            int stopIndex  = xmlElementSyntax.Content.IndexOf(stopNode);

            if (startIndex < 0 || stopIndex < 0)
            {
                return(document);
            }

            XmlElementSyntax           paragraph = XmlSyntaxFactory.ParaElement(xmlElementSyntax.Content.Skip(startIndex).Take(stopIndex - startIndex + 1).ToArray());
            SyntaxList <XmlNodeSyntax> leadingWhitespaceContent;
            SyntaxList <XmlNodeSyntax> trailingWhitespaceContent;

            paragraph = TrimWhitespaceContent(paragraph, out leadingWhitespaceContent, out trailingWhitespaceContent);

            SyntaxList <XmlNodeSyntax> newContent = XmlSyntaxFactory.List();

            newContent = newContent.AddRange(xmlElementSyntax.Content.Take(startIndex));
            newContent = newContent.AddRange(leadingWhitespaceContent);
            newContent = newContent.Add(paragraph);
            newContent = newContent.AddRange(trailingWhitespaceContent);
            newContent = newContent.AddRange(xmlElementSyntax.Content.Skip(stopIndex + 1));
            return(document.WithSyntaxRoot(root.ReplaceNode(xmlElementSyntax, xmlElementSyntax.WithContent(newContent))));
        }