diff --git a/src/Docfx.Dotnet/Parsers/XmlComment.cs b/src/Docfx.Dotnet/Parsers/XmlComment.cs index a3359a89e9e..3c89b5fc7da 100644 --- a/src/Docfx.Dotnet/Parsers/XmlComment.cs +++ b/src/Docfx.Dotnet/Parsers/XmlComment.cs @@ -142,7 +142,18 @@ private void ResolveCode(XDocument doc, XmlCommentParserContext context) var (lang, value) = ResolveCodeSource(node, context); value = TrimEachLine(value ?? node.Value, new(' ', indent)); var code = new XElement("code", value); - code.SetAttributeValue("class", $"lang-{lang ?? "csharp"}"); + + if (node.Attribute("language") is { } languageAttribute) + { + lang = languageAttribute.Value; + } + + if (string.IsNullOrEmpty(lang)) + { + lang = "csharp"; + } + + code.SetAttributeValue("class", $"lang-{lang}"); node.ReplaceWith(new XElement("pre", code)); } } diff --git a/test/Docfx.Dotnet.Tests/XmlCommentUnitTest.cs b/test/Docfx.Dotnet.Tests/XmlCommentUnitTest.cs index 875db25cd76..36f14770c19 100644 --- a/test/Docfx.Dotnet.Tests/XmlCommentUnitTest.cs +++ b/test/Docfx.Dotnet.Tests/XmlCommentUnitTest.cs @@ -325,7 +325,7 @@ Classes in assemblies are by definition complete. example
This is ref
a sample of exception node
public class XmlElement
+ public class XmlElement
: XmlLinkedNode
-
word inside list->listItem->list->listItem->para.>
diff --git a/test/docfx.Snapshot.Tests/SamplesTest.Seed/api/CatLibrary.Cat-2.html.view.verified.json b/test/docfx.Snapshot.Tests/SamplesTest.Seed/api/CatLibrary.Cat-2.html.view.verified.json
index 5f227d2a737..e7bda20f8f2 100644
--- a/test/docfx.Snapshot.Tests/SamplesTest.Seed/api/CatLibrary.Cat-2.html.view.verified.json
+++ b/test/docfx.Snapshot.Tests/SamplesTest.Seed/api/CatLibrary.Cat-2.html.view.verified.json
@@ -3693,7 +3693,7 @@
"summary": "
Here's main class of this Demo.
\nYou can see mostly type of article within this class and you for more detail, please see the remarks.
\n\nthis class is a template class. It has two Generic parameter. they are: T
and K
.
\nThe extension method of this class can refer to class
\n",
"remarks": "THIS is remarks overridden in MARKDWON file
\n",
"example": [
- "Here's example of how to create an instance of this class. As T is limited with class
and K is limited with struct
.
\nvar a = new Cat(object, int)();\nint catNumber = new int();\nunsafe\n{\n a.GetFeetLength(catNumber);\n}
\nAs you see, here we bring in pointer so we need to add unsafe
keyword.
\n"
+ "Here's example of how to create an instance of this class. As T is limited with class
and K is limited with struct
.
\nvar a = new Cat(object, int)();\nint catNumber = new int();\nunsafe\n{\n a.GetFeetLength(catNumber);\n}
\nAs you see, here we bring in pointer so we need to add unsafe
keyword.
\n"
],
"syntax": {
"content": [
diff --git a/test/docfx.Snapshot.Tests/SamplesTest.SeedHtml/1920x1080/api-CatLibrary.Cat-2.html-q-cat.verified.png b/test/docfx.Snapshot.Tests/SamplesTest.SeedHtml/1920x1080/api-CatLibrary.Cat-2.html-q-cat.verified.png
index 5aeb9358011..589c2a50e8b 100644
--- a/test/docfx.Snapshot.Tests/SamplesTest.SeedHtml/1920x1080/api-CatLibrary.Cat-2.html-q-cat.verified.png
+++ b/test/docfx.Snapshot.Tests/SamplesTest.SeedHtml/1920x1080/api-CatLibrary.Cat-2.html-q-cat.verified.png
@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
-oid sha256:d04890f4eaf9998cffbd4481f1a6961f6668ee26061c8ce2b24394c5a9e2d1ca
-size 833454
+oid sha256:c29d9342e3b4f0864c69cc39d180220ad9c23812f4c640e2c2e916f6a81648a5
+size 833585
diff --git a/test/docfx.Snapshot.Tests/SamplesTest.SeedHtml/375x812/api-CatLibrary.Cat-2.html-q-cat.verified.png b/test/docfx.Snapshot.Tests/SamplesTest.SeedHtml/375x812/api-CatLibrary.Cat-2.html-q-cat.verified.png
index fc8af79ab32..61b1bfe10e0 100644
--- a/test/docfx.Snapshot.Tests/SamplesTest.SeedHtml/375x812/api-CatLibrary.Cat-2.html-q-cat.verified.png
+++ b/test/docfx.Snapshot.Tests/SamplesTest.SeedHtml/375x812/api-CatLibrary.Cat-2.html-q-cat.verified.png
@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
-oid sha256:3e64015b37c91f3e5b4c95ef54393014be1ab3e6ae8551cd0aab37c48a315fa3
-size 667755
+oid sha256:ef3fde1c7d93a26dcd5420bb8302efdaf6cff5d4adf7cfdb2c81804b9dd70992
+size 666999
diff --git a/test/docfx.Snapshot.Tests/SamplesTest.SeedHtml/html/api-CatLibrary.Cat-2.html-q-cat.verified.html b/test/docfx.Snapshot.Tests/SamplesTest.SeedHtml/html/api-CatLibrary.Cat-2.html-q-cat.verified.html
index 12ec7f09d22..31aef1ed32c 100644
--- a/test/docfx.Snapshot.Tests/SamplesTest.SeedHtml/html/api-CatLibrary.Cat-2.html-q-cat.verified.html
+++ b/test/docfx.Snapshot.Tests/SamplesTest.SeedHtml/html/api-CatLibrary.Cat-2.html-q-cat.verified.html
@@ -458,9 +458,9 @@ Type ParametersExamples
Here's example of how to create an instance of this class. As T is limited with class
and K is limited with struct
.
-var a = new Cat(object, int)();
-int catNumber = new int();
-unsafe
+var a = new Cat(object, int)();
+int catNumber = new int();
+unsafe
{
a.GetFeetLength(catNumber);
}