fix: constrain greedy code block match

This commit is contained in:
Solomon Victorino 2024-03-28 14:16:21 -06:00
parent 066a3fdaff
commit f7ae1a623c

View file

@ -73,7 +73,7 @@ func stripBlockTags(content string) (result string) {
return return
} }
var codeBlockRegex = regexp.MustCompile(`(?s)<pre(?:.+?lang-(.+?)[\s"'])?.*?><code>(.*?)<\/code><\/pre>`) var codeBlockRegex = regexp.MustCompile(`(?s)<pre(?:[^>]+?lang-(.+?)[\s"'])?.*?><code>(.*?)<\/code><\/pre>`)
// HighlightCodeBlocks uses both highlightSyntaxViaContent stripCodeBlocks and returns the newly highlighted code HTML. // HighlightCodeBlocks uses both highlightSyntaxViaContent stripCodeBlocks and returns the newly highlighted code HTML.
func HighlightCodeBlocks(html string) string { func HighlightCodeBlocks(html string) string {