Skip to content

Commit

Permalink
fix: angle bracket escape in code inline (dotnet#8630)
Browse files Browse the repository at this point in the history
  • Loading branch information
yufeih authored and p-kostov committed Jun 28, 2024
1 parent 664782f commit 3537221
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 14 deletions.
2 changes: 2 additions & 0 deletions samples/seed/dotnet/project/Project/Class1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ public void Issue2623() { }
/// > [!NOTE]
/// > This is a <note>. & " '
///
/// Inline `<angle brackets>`.
///
/// [link](https://www.github.com "title")
///
/// ```csharp
Expand Down
4 changes: 2 additions & 2 deletions src/Microsoft.DocAsCode.Dotnet/Parsers/XmlComment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -569,15 +569,15 @@ static void DecodeMarkdownCode(MarkdownObject node)
switch (node)
{
case CodeInline codeInline:
codeInline.Content = XmlDecode(codeInline.Content);
codeInline.ContentWithTrivia = new(XmlDecode(codeInline.ContentWithTrivia.ToString()), codeInline.ContentWithTrivia.NewLine);
break;

case CodeBlock codeBlock:
var lines = new StringLineGroup(codeBlock.Lines.Count);
foreach (var line in codeBlock.Lines.Lines)
{
var newLine = line;
newLine.Slice = new StringSlice(XmlDecode(line.Slice.ToString()), line.Slice.NewLine);
newLine.Slice = new(XmlDecode(line.Slice.ToString()), line.Slice.NewLine);
lines.Add(newLine);
}
codeBlock.Lines = lines;
Expand Down
6 changes: 6 additions & 0 deletions test/Microsoft.DocAsCode.Dotnet.Tests/XmlCommentUnitTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,12 @@ function main()
""", comment.Remarks, ignoreLineEndingDifferences: true);
}

[Fact]
public static void MarkdownCodeInline()
{
Verify("Inline `&lt;angle brackets&gt;`", "Inline `<angle brackets>`");
}

[Fact]
public void TestXmlCommentParser()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -389,15 +389,15 @@
},
"id": "Issue2723",
"path": "dotnet/project/Project/Class1.cs",
"startLine": 92.0,
"startLine": 94.0,
"endLine": 0.0,
"isExternal": false
},
"assemblies": [
"BuildFromProject"
],
"namespace": "BuildFromProject",
"remarks": "<div class=\"NOTE\" sourcefile=\"obj/api/BuildFromProject.Class1.yml\" sourcestartlinenumber=\"1\">\n<h5>Note</h5>\n<p sourcefile=\"obj/api/BuildFromProject.Class1.yml\" sourcestartlinenumber=\"2\">This is a &lt;note&gt;. &amp; &quot; '</p>\n</div>\n<p sourcefile=\"obj/api/BuildFromProject.Class1.yml\" sourcestartlinenumber=\"4\"><a href=\"https://www.github.com\" sourcefile=\"obj/api/BuildFromProject.Class1.yml\" sourcestartlinenumber=\"4\" title=\"title\">link</a></p>\n<pre><code class=\"lang-csharp\" sourcefile=\"obj/api/BuildFromProject.Class1.yml\" sourcestartlinenumber=\"6\">for (var i = 0; i &gt; 10; i++) // &amp; &quot; '\nvar range = new Range&lt;int&gt; { Min = 0, Max = 10 };\n</code></pre>\n<pre><code class=\"lang-csharp\">var range = new Range&lt;int&gt; { Min = 0, Max = 10 };</code></pre>\n",
"remarks": "<div class=\"NOTE\" sourcefile=\"obj/api/BuildFromProject.Class1.yml\" sourcestartlinenumber=\"1\">\n<h5>Note</h5>\n<p sourcefile=\"obj/api/BuildFromProject.Class1.yml\" sourcestartlinenumber=\"2\">This is a &lt;note&gt;. &amp; &quot; '</p>\n</div>\n<p sourcefile=\"obj/api/BuildFromProject.Class1.yml\" sourcestartlinenumber=\"4\">Inline <code sourcefile=\"obj/api/BuildFromProject.Class1.yml\" sourcestartlinenumber=\"4\">&lt;angle brackets&gt;</code>.</p>\n<p sourcefile=\"obj/api/BuildFromProject.Class1.yml\" sourcestartlinenumber=\"6\"><a href=\"https://www.github.com\" sourcefile=\"obj/api/BuildFromProject.Class1.yml\" sourcestartlinenumber=\"6\" title=\"title\">link</a></p>\n<pre><code class=\"lang-csharp\" sourcefile=\"obj/api/BuildFromProject.Class1.yml\" sourcestartlinenumber=\"8\">for (var i = 0; i &gt; 10; i++) // &amp; &quot; '\nvar range = new Range&lt;int&gt; { Min = 0, Max = 10 };\n</code></pre>\n<pre><code class=\"lang-csharp\">var range = new Range&lt;int&gt; { Min = 0, Max = 10 };</code></pre>\n",
"example": [],
"overload": {
"uid": "BuildFromProject.Class1.Issue2723*",
Expand Down Expand Up @@ -448,7 +448,7 @@
"summary": "",
"platform": null,
"docurl": "https://github.com/dotnet/docfx/new/main/apiSpec/new?filename=BuildFromProject_Class1_Issue2723.md&value=---%0Auid%3A%20BuildFromProject.Class1.Issue2723%0Asummary%3A%20'*You%20can%20override%20summary%20for%20the%20API%20here%20using%20*MARKDOWN*%20syntax'%0A---%0A%0A*Please%20type%20below%20more%20information%20about%20this%20API%3A*%0A%0A",
"sourceurl": "https://github.com/dotnet/docfx/blob/main/samples/seed/dotnet/project/Project/Class1.cs/#L93",
"sourceurl": "https://github.com/dotnet/docfx/blob/main/samples/seed/dotnet/project/Project/Class1.cs/#L95",
"conceptual": "",
"implements": "",
"seealso": null,
Expand Down Expand Up @@ -657,7 +657,7 @@
},
"id": "Issue4392",
"path": "dotnet/project/Project/Class1.cs",
"startLine": 97.0,
"startLine": 99.0,
"endLine": 0.0,
"isExternal": false
},
Expand Down Expand Up @@ -716,7 +716,7 @@
"summary": "",
"platform": null,
"docurl": "https://github.com/dotnet/docfx/new/main/apiSpec/new?filename=BuildFromProject_Class1_Issue4392.md&value=---%0Auid%3A%20BuildFromProject.Class1.Issue4392%0Asummary%3A%20'*You%20can%20override%20summary%20for%20the%20API%20here%20using%20*MARKDOWN*%20syntax'%0A---%0A%0A*Please%20type%20below%20more%20information%20about%20this%20API%3A*%0A%0A",
"sourceurl": "https://github.com/dotnet/docfx/blob/main/samples/seed/dotnet/project/Project/Class1.cs/#L98",
"sourceurl": "https://github.com/dotnet/docfx/blob/main/samples/seed/dotnet/project/Project/Class1.cs/#L100",
"conceptual": "",
"implements": "",
"seealso": null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"api/BuildFromProject.Class1.html": {
"href": "api/BuildFromProject.Class1.html",
"title": "Class Class1 | docfx seed website",
"keywords": "Class Class1 Namespace BuildFromProject Assembly BuildFromProject.dll public class Class1 Inheritance object Class1 Inherited Members object.Equals(object) object.Equals(object, object) object.GetHashCode() object.GetType() object.MemberwiseClone() object.ReferenceEquals(object, object) object.ToString() Methods Issue1651() Pricing models are used to calculate theoretical option values 1Black Scholes 2Black76 3Black76Fut 4Equity Tree 5Variance Swap 6Dividend Forecast public void Issue1651() Issue2623() public void Issue2623() Examples MyClass myClass = new MyClass(); void Update() { myClass.Execute(); } Remarks For example: MyClass myClass = new MyClass(); void Update() { myClass.Execute(); } Issue2723() public void Issue2723() Remarks Note This is a <note>. & \" ' link for (var i = 0; i > 10; i++) // & \" ' var range = new Range<int> { Min = 0, Max = 10 }; var range = new Range<int> { Min = 0, Max = 10 }; Issue4017() public void Issue4017() Examples public void HookMessageDeleted(BaseSocketClient client) { client.MessageDeleted += HandleMessageDelete; } public Task HandleMessageDelete(Cacheable<IMessage, ulong> cachedMessage, ISocketMessageChannel channel) { // check if the message exists in cache; if not, we cannot report what was removed if (!cachedMessage.HasValue) return; var message = cachedMessage.Value; Console.WriteLine($\"A message ({message.Id}) from {message.Author} was removed from the channel {channel.Name} ({channel.Id}):\" + Environment.NewLine + message.Content); return Task.CompletedTask; } Remarks void Update() { myClass.Execute(); } Issue4392() public void Issue4392() Remarks @\"\\\\?\\\" @\"\\\\?\\\" Issue7484() public void Issue7484() Remarks There's really no reason to not believe that this class can test things. Term Description A Term A Description Bee Term Bee Description Issue896() Test public void Issue896() See Also Class1.Test<T> XmlCommentIncludeTag() This method should do something... public void XmlCommentIncludeTag() Remarks This is remarks."
"keywords": "Class Class1 Namespace BuildFromProject Assembly BuildFromProject.dll public class Class1 Inheritance object Class1 Inherited Members object.Equals(object) object.Equals(object, object) object.GetHashCode() object.GetType() object.MemberwiseClone() object.ReferenceEquals(object, object) object.ToString() Methods Issue1651() Pricing models are used to calculate theoretical option values 1Black Scholes 2Black76 3Black76Fut 4Equity Tree 5Variance Swap 6Dividend Forecast public void Issue1651() Issue2623() public void Issue2623() Examples MyClass myClass = new MyClass(); void Update() { myClass.Execute(); } Remarks For example: MyClass myClass = new MyClass(); void Update() { myClass.Execute(); } Issue2723() public void Issue2723() Remarks Note This is a <note>. & \" ' Inline <angle brackets>. link for (var i = 0; i > 10; i++) // & \" ' var range = new Range<int> { Min = 0, Max = 10 }; var range = new Range<int> { Min = 0, Max = 10 }; Issue4017() public void Issue4017() Examples public void HookMessageDeleted(BaseSocketClient client) { client.MessageDeleted += HandleMessageDelete; } public Task HandleMessageDelete(Cacheable<IMessage, ulong> cachedMessage, ISocketMessageChannel channel) { // check if the message exists in cache; if not, we cannot report what was removed if (!cachedMessage.HasValue) return; var message = cachedMessage.Value; Console.WriteLine($\"A message ({message.Id}) from {message.Author} was removed from the channel {channel.Name} ({channel.Id}):\" + Environment.NewLine + message.Content); return Task.CompletedTask; } Remarks void Update() { myClass.Execute(); } Issue4392() public void Issue4392() Remarks @\"\\\\?\\\" @\"\\\\?\\\" Issue7484() public void Issue7484() Remarks There's really no reason to not believe that this class can test things. Term Description A Term A Description Bee Term Bee Description Issue896() Test public void Issue896() See Also Class1.Test<T> XmlCommentIncludeTag() This method should do something... public void XmlCommentIncludeTag() Remarks This is remarks."
},
"api/BuildFromProject.Class1.Test-1.html": {
"href": "api/BuildFromProject.Class1.Test-1.html",
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,7 @@ <h4 class="section" id="BuildFromProject_Class1_Issue2623_remarks">Remarks<a cla

<h3 id="BuildFromProject_Class1_Issue2723" data-uid="BuildFromProject.Class1.Issue2723">
Issue2723()
<a class="header-action link-secondary" title="View source" href="https://github.com/dotnet/docfx/blob/main/samples/seed/dotnet/project/Project/Class1.cs/#L93"><i class="bi bi-code-slash"></i></a>
<a class="header-action link-secondary" title="View source" href="https://github.com/dotnet/docfx/blob/main/samples/seed/dotnet/project/Project/Class1.cs/#L95"><i class="bi bi-code-slash"></i></a>
<a class="anchorjs-link " aria-label="Anchor" data-anchorjs-icon="#" href="#BuildFromProject_Class1_Issue2723" style="margin-left: 0.1875em; padding-right: 0.1875em; padding-left: 0.1875em;"></a></h3>

<div class="markdown level1 summary"></div>
Expand All @@ -634,6 +634,7 @@ <h4 class="section" id="BuildFromProject_Class1_Issue2723_remarks">Remarks<a cla
<h5>Note</h5>
<p>This is a &lt;note&gt;. &amp; " '</p>
</div>
<p>Inline <code>&lt;angle brackets&gt;</code>.</p>
<p><a href="https://www.github.com" title="title" target="_blank" rel="noopener noreferrer nofollow" class="external">link</a></p>
<pre><code class="lang-csharp hljs language-csharp"><span class="hljs-keyword">for</span> (<span class="hljs-keyword">var</span> i = <span class="hljs-number">0</span>; i &gt; <span class="hljs-number">10</span>; i++) <span class="hljs-comment">// &amp; " '</span>
<span class="hljs-keyword">var</span> range = <span class="hljs-keyword">new</span> Range&lt;<span class="hljs-built_in">int</span>&gt; { Min = <span class="hljs-number">0</span>, Max = <span class="hljs-number">10</span> };
Expand Down Expand Up @@ -697,7 +698,7 @@ <h4 class="section" id="BuildFromProject_Class1_Issue4017_remarks">Remarks<a cla

<h3 id="BuildFromProject_Class1_Issue4392" data-uid="BuildFromProject.Class1.Issue4392">
Issue4392()
<a class="header-action link-secondary" title="View source" href="https://github.com/dotnet/docfx/blob/main/samples/seed/dotnet/project/Project/Class1.cs/#L98"><i class="bi bi-code-slash"></i></a>
<a class="header-action link-secondary" title="View source" href="https://github.com/dotnet/docfx/blob/main/samples/seed/dotnet/project/Project/Class1.cs/#L100"><i class="bi bi-code-slash"></i></a>
<a class="anchorjs-link " aria-label="Anchor" data-anchorjs-icon="#" href="#BuildFromProject_Class1_Issue4392" style="margin-left: 0.1875em; padding-right: 0.1875em; padding-left: 0.1875em;"></a></h3>

<div class="markdown level1 summary"></div>
Expand Down

0 comments on commit 3537221

Please sign in to comment.