Make Markdown fenced code block work with more syntaxes (#37154)

This commit is contained in:
wxiaoguang
2026-04-10 07:54:39 +08:00
committed by GitHub
parent c10a5b908a
commit 45c80bfec1
3 changed files with 53 additions and 0 deletions
+19
View File
@@ -600,3 +600,22 @@ func TestMarkdownUlDir(t *testing.T) {
</ul>
`, string(result))
}
func TestMarkdownFencedCodeBlock(t *testing.T) {
testRender := func(input, expected string) {
buffer, err := markdown.RenderString(markup.NewTestRenderContext(), input)
assert.NoError(t, err)
assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(string(buffer)))
}
const nl = "\n"
const prefix = `<div class="code-block-container code-overflow-scroll"><pre class="code-block">`
const suffix = `</pre></div>`
testRender("```\ncode\n```", prefix+`<code class="chroma language-text display">code`+nl+`</code>`+suffix)
const jsCommon = prefix + `<code class="chroma language-js display"><span class="nx">code</span>` + nl + `</code>` + suffix
testRender("```js\ncode\n```", jsCommon)
testRender("```js:app.ts\ncode\n```", jsCommon)
testRender("```js,ignore\ncode\n```", jsCommon)
testRender("```js ignore\ncode\n```", jsCommon)
}