Skip to content

Commit 22d6d6f

Browse files
filzrevp-kostov
authored andcommitted
fix: Broken examples problems when using inheritdoc tag (dotnet#9754)
* fix: Broken examples problems when using inheritdoc tag * chore: fix tests that failed by xml formatting
1 parent b0bdcfa commit 22d6d6f

2 files changed

Lines changed: 16 additions & 9 deletions

File tree

src/Docfx.Dotnet/Parsers/XmlComment.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@ public static XmlComment Parse(string xml, XmlCommentParserContext context = nul
112112
}
113113
try
114114
{
115+
// Format xml with indentation.
116+
// It's needed to fix issue (https://github.com/dotnet/docfx/issues/9736)
117+
xml = XElement.Parse(xml).ToString(SaveOptions.None);
118+
115119
return new XmlComment(xml, context ?? new());
116120
}
117121
catch (XmlException)

test/Docfx.Dotnet.Tests/XmlCommentUnitTest.cs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ public static void ParaNewLine()
2828
Assert.Equal(
2929
"""
3030
a
31-
<p>b</p>
32-
<p>c</p>
31+
<p>b</p><p>c</p>
3332
""",
3433
XmlComment.Parse("""
3534
<summary>
@@ -53,8 +52,10 @@ public static void Issue4165()
5352
{
5453
var comment = XmlComment.Parse(
5554
"""
56-
<param name="args">arg1</param>
57-
<param name="args">arg2</param>
55+
<doc>
56+
<param name="args">arg1</param>
57+
<param name="args">arg2</param>
58+
</doc>
5859
""");
5960
Assert.Equal("arg1", comment.Parameters["args"]);
6061
}
@@ -205,6 +206,7 @@ public static void MarkdownCodeBlock()
205206
{
206207
var comment = XmlComment.Parse(
207208
"""
209+
<doc>
208210
<summary>
209211
public int Main(string[] args)
210212
{
@@ -226,6 +228,7 @@ function main()
226228
}
227229
```
228230
</remarks>
231+
</doc>
229232
""");
230233

231234
Assert.Equal("""
@@ -289,7 +292,7 @@ Classes in assemblies are by definition complete.
289292
<remarks>
290293
<see href="https://example.org"/>
291294
<see href="https://example.org">example</see>
292-
<para>This is <paramref name='ref'/> <paramref />a sample of exception node</para>
295+
<para>This is <paramref name='ref'/><paramref /> a sample of exception node</para>
293296
<list type='bullet'>
294297
<item>
295298
<description>
@@ -387,13 +390,13 @@ Classes in assemblies are by definition complete.
387390
<a href="https://example.org">example</a>
388391
<p>This is <code class="paramref">ref</code> a sample of exception node</p>
389392
<ul><li>
390-
<pre><code class="lang-c#">public class XmlElement
391-
: XmlLinkedNode</code></pre>
392-
<ol><li>
393+
<pre><code class="lang-c#">public class XmlElement
394+
: XmlLinkedNode</code></pre>
395+
<ol><li>
393396
word inside list-&gt;listItem-&gt;list-&gt;listItem-&gt;para.&gt;
394397
the second line.
395398
</li><li>item2 in numbered list</li></ol>
396-
</li><li>item2 in bullet list</li><li>
399+
</li><li>item2 in bullet list</li><li>
397400
loose text <i>not</i> wrapped in description
398401
</li></ul>
399402
""", remarks, ignoreLineEndingDifferences: true);

0 commit comments

Comments
 (0)