Refactor markdown render (#32736)

and add some tests
This commit is contained in:
wxiaoguang 2024-12-06 20:00:24 +08:00 committed by GitHub
parent b32f0cdfa0
commit 3c4a06273f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 101 additions and 32 deletions

View file

@ -68,7 +68,7 @@ func TestMathRender(t *testing.T) {
},
{
"$$a$$",
`<pre class="code-block is-loading"><code class="chroma language-math display">a</code></pre>` + nl,
`<code class="chroma language-math display">a</code>` + nl,
},
{
"$$a$$ test",
@ -79,9 +79,13 @@ func TestMathRender(t *testing.T) {
`<p>test <code class="language-math display is-loading">a</code></p>` + nl,
},
{
"foo $x=\\$$ bar",
`foo $x=\$$ bar`,
`<p>foo <code class="language-math is-loading">x=\$</code> bar</p>` + nl,
},
{
`$\text{$b$}$`,
`<p><code class="language-math is-loading">\text{$b$}</code></p>` + nl,
},
}
for _, test := range testcases {
@ -124,14 +128,36 @@ func TestMathRenderBlockIndent(t *testing.T) {
`,
},
{
"indent-2",
"indent-2-mismatch",
`
\[
\alpha
a
b
c
d
\]
`,
`<pre class="code-block is-loading"><code class="chroma language-math display">
\alpha
a
b
c
d
</code></pre>
`,
},
{
"indent-2",
`
\[
a
b
c
\]
`,
`<pre class="code-block is-loading"><code class="chroma language-math display">
a
b
c
</code></pre>
`,
},
@ -139,7 +165,7 @@ func TestMathRenderBlockIndent(t *testing.T) {
"indent-0-oneline",
`$$ x $$
foo`,
`<pre class="code-block is-loading"><code class="chroma language-math display"> x </code></pre>
`<code class="chroma language-math display"> x </code>
<p>foo</p>
`,
},
@ -147,8 +173,46 @@ foo`,
"indent-3-oneline",
` $$ x $$<SPACE>
foo`,
`<pre class="code-block is-loading"><code class="chroma language-math display"> x </code></pre>
`<code class="chroma language-math display"> x </code>
<p>foo</p>
`,
},
{
"quote-block",
`
> \[
> a
> \]
> \[
> b
> \]
`,
`<blockquote>
<pre class="code-block is-loading"><code class="chroma language-math display">
a
</code></pre>
<pre class="code-block is-loading"><code class="chroma language-math display">
b
</code></pre>
</blockquote>
`,
},
{
"list-block",
`
1. a
\[
x
\]
2. b`,
`<ol>
<li>a
<pre class="code-block is-loading"><code class="chroma language-math display">
x
</code></pre>
</li>
<li>b</li>
</ol>
`,
},
}