Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Broken examples problems when using inheritdoc tag #9754

Merged
merged 2 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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