diff --git a/src/Docfx.Dotnet/Parsers/XmlComment.cs b/src/Docfx.Dotnet/Parsers/XmlComment.cs index 823e7a92c12..2406b90aa6f 100644 --- a/src/Docfx.Dotnet/Parsers/XmlComment.cs +++ b/src/Docfx.Dotnet/Parsers/XmlComment.cs @@ -112,6 +112,10 @@ public static XmlComment Parse(string xml, XmlCommentParserContext context = nul } try { + // Format xml with indentation. + // It's needed to fix issue (https://github.com/dotnet/docfx/issues/9736) + xml = XElement.Parse(xml).ToString(SaveOptions.None); + return new XmlComment(xml, context ?? new()); } catch (XmlException) diff --git a/test/Docfx.Dotnet.Tests/XmlCommentUnitTest.cs b/test/Docfx.Dotnet.Tests/XmlCommentUnitTest.cs index 698e3b910ab..37524281fb0 100644 --- a/test/Docfx.Dotnet.Tests/XmlCommentUnitTest.cs +++ b/test/Docfx.Dotnet.Tests/XmlCommentUnitTest.cs @@ -28,8 +28,7 @@ public static void ParaNewLine() Assert.Equal( """ a -

b

-

c

+

b

c

""", XmlComment.Parse(""" @@ -53,8 +52,10 @@ public static void Issue4165() { var comment = XmlComment.Parse( """ - arg1 - arg2 + + arg1 + arg2 + """); Assert.Equal("arg1", comment.Parameters["args"]); } @@ -205,6 +206,7 @@ public static void MarkdownCodeBlock() { var comment = XmlComment.Parse( """ + public int Main(string[] args) { @@ -226,6 +228,7 @@ function main() } ``` + """); Assert.Equal(""" @@ -289,7 +292,7 @@ Classes in assemblies are by definition complete. example - This is a sample of exception node + This is a sample of exception node @@ -387,13 +390,13 @@ Classes in assemblies are by definition complete. example

This is ref a sample of exception node

  • -
    public class XmlElement
    -                            : XmlLinkedNode
    -
    1. +
      public class XmlElement
      +                      : XmlLinkedNode
      +
      1. word inside list->listItem->list->listItem->para.> the second line.
      2. item2 in numbered list
      -
    2. item2 in bullet list
    3. +
    4. item2 in bullet list
    5. loose text not wrapped in description
""", remarks, ignoreLineEndingDifferences: true);