Skip to content

Commit a3849ed

Browse files
camdritJan0660
authored andcommitted
Add support for code blocks in other languages
1 parent 4af5cf9 commit a3849ed

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

Program.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
var xrefRegex = new Regex("<xref href=\"(.+?)\" data-throw-if-not-resolved=\"false\"></xref>", RegexOptions.Compiled);
2424
var langwordXrefRegex =
2525
new Regex("<xref uid=\"langword_csharp_.+?\" name=\"(.+?)\" href=\"\"></xref>", RegexOptions.Compiled);
26-
var codeBlockRegex = new Regex("<pre><code class=\"lang-csharp\">((.|\n)+?)</code></pre>", RegexOptions.Compiled);
26+
var codeBlockRegex = new Regex("<pre><code class=\"lang-([a-zA-Z0-9]+)\">((.|\n)+?)</code></pre>", RegexOptions.Compiled);
2727
var codeRegex = new Regex("<code>(.+?)</code>", RegexOptions.Compiled);
2828
var linkRegex = new Regex("<a href=\"(.+?)\">(.+?)</a>", RegexOptions.Compiled);
2929
var brRegex = new Regex("<br */?>", RegexOptions.Compiled);
@@ -210,7 +210,7 @@ string Link(string uid, bool linkFromGroupedType, bool nameOnly = false, bool li
210210
return Link(uid, linkFromGroupedType);
211211
});
212212
summary = langwordXrefRegex.Replace(summary, match => $"`{match.Groups[1].Value}`");
213-
summary = codeBlockRegex.Replace(summary, match => $"```csharp\n{match.Groups[1].Value.Trim()}\n```");
213+
summary = codeBlockRegex.Replace(summary, match => $"```{match.Groups[1].Value.Trim()}\n{match.Groups[2].Value.Trim()}\n```");
214214
summary = codeRegex.Replace(summary, match => $"`{match.Groups[1].Value}`");
215215
summary = linkRegex.Replace(summary, match => $"[{match.Groups[2].Value}]({match.Groups[1].Value})");
216216
summary = brRegex.Replace(summary, _ => config.BrNewline);

0 commit comments

Comments
 (0)