Skip to content

Commit

Permalink
fix: Broken examples problems when using inheritdoc tag (#9754)
Browse files Browse the repository at this point in the history
* fix: Broken examples problems when using inheritdoc tag

* chore: fix tests that failed by xml formatting
  • Loading branch information
filzrev authored Mar 12, 2024
1 parent 7e8d455 commit ca358a5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
4 changes: 4 additions & 0 deletions src/Docfx.Dotnet/Parsers/XmlComment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
21 changes: 12 additions & 9 deletions test/Docfx.Dotnet.Tests/XmlCommentUnitTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ public static void ParaNewLine()
Assert.Equal(
"""
a
<p>b</p>
<p>c</p>
<p>b</p><p>c</p>
""",
XmlComment.Parse("""
<summary>
Expand All @@ -53,8 +52,10 @@ public static void Issue4165()
{
var comment = XmlComment.Parse(
"""
<param name="args">arg1</param>
<param name="args">arg2</param>
<doc>
<param name="args">arg1</param>
<param name="args">arg2</param>
</doc>
""");
Assert.Equal("arg1", comment.Parameters["args"]);
}
Expand Down Expand Up @@ -205,6 +206,7 @@ public static void MarkdownCodeBlock()
{
var comment = XmlComment.Parse(
"""
<doc>
<summary>
public int Main(string[] args)
{
Expand All @@ -226,6 +228,7 @@ function main()
}
```
</remarks>
</doc>
""");

Assert.Equal("""
Expand Down Expand Up @@ -289,7 +292,7 @@ Classes in assemblies are by definition complete.
<remarks>
<see href="https://example.org"/>
<see href="https://example.org">example</see>
<para>This is <paramref name='ref'/> <paramref />a sample of exception node</para>
<para>This is <paramref name='ref'/><paramref /> a sample of exception node</para>
<list type='bullet'>
<item>
<description>
Expand Down Expand Up @@ -387,13 +390,13 @@ Classes in assemblies are by definition complete.
<a href="https://example.org">example</a>
<p>This is <code class="paramref">ref</code> a sample of exception node</p>
<ul><li>
<pre><code class="lang-c#">public class XmlElement
: XmlLinkedNode</code></pre>
<ol><li>
<pre><code class="lang-c#">public class XmlElement
: XmlLinkedNode</code></pre>
<ol><li>
word inside list-&gt;listItem-&gt;list-&gt;listItem-&gt;para.&gt;
the second line.
</li><li>item2 in numbered list</li></ol>
</li><li>item2 in bullet list</li><li>
</li><li>item2 in bullet list</li><li>
loose text <i>not</i> wrapped in description
</li></ul>
""", remarks, ignoreLineEndingDifferences: true);
Expand Down

0 comments on commit ca358a5

Please sign in to comment.