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