1
0
Fork 0
mirror of https://codeberg.org/forgejo/forgejo.git synced 2025-08-02 08:25:20 +02:00

fix: enable multi-line math equations in wiki (#8424)

- When math equation support was added into Gitea it allowed for math equations to be typed over multiple lines via `\[ ... \]` and `$$ ... $$`. Specifically the former delimiters caused problems with legitimate markdown input to be seen as a math equation and therefore was disabled in e1a82a15d3.
- Enable this multi-line parsing for wiki as it's less likely to cause issues in the context of the wiki.
- It is hard to fix this issue in a proper way without investing a good amount of time in Goldmark as explained in https://codeberg.org/forgejo/forgejo/issues/6902#issuecomment-2845317
- Added unit test.
- Resolves forgejo/forgejo#6902

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/8424
Reviewed-by: Earl Warren <earl-warren@noreply.codeberg.org>
Co-authored-by: Gusted <postmaster@gusted.xyz>
Co-committed-by: Gusted <postmaster@gusted.xyz>
This commit is contained in:
Gusted 2025-07-06 22:00:09 +02:00 committed by Gusted
parent f5cbb9604d
commit da1c0f7f18
5 changed files with 56 additions and 9 deletions

View file

@ -561,6 +561,14 @@ func TestMathBlock(t *testing.T) {
"test $$a$$",
`<p>test <code class="language-math display is-loading">a</code></p>` + nl,
},
{
`\[
[\triangle ABC] = \sqrt{s(s-a)(s-b)(s-c)}
\]`,
`<p>[<br/>
[\triangle ABC] = \sqrt{s(s-a)(s-b)(s-c)}<br/>
]</p>` + nl,
},
}
for _, test := range testcases {
@ -568,6 +576,32 @@ func TestMathBlock(t *testing.T) {
require.NoError(t, err, "Unexpected error in testcase: %q", test.testcase)
assert.Equal(t, template.HTML(test.expected), res, "Unexpected result in testcase %q", test.testcase)
}
t.Run("Wiki context", func(t *testing.T) {
testcases := []struct {
testcase string
expected string
}{
{
"$a$",
`<p><code class="language-math is-loading">a</code></p>` + nl,
},
{
`\[
[\triangle ABC] = \sqrt{s(s-a)(s-b)(s-c)}
\]`,
`<pre class="code-block is-loading"><code class="chroma language-math display">
[\triangle ABC] = \sqrt{s(s-a)(s-b)(s-c)}
</code></pre>` + nl,
},
}
for _, test := range testcases {
res, err := markdown.RenderString(&markup.RenderContext{Ctx: git.DefaultContext, IsWiki: true}, test.testcase)
require.NoError(t, err, "Unexpected error in testcase: %q", test.testcase)
assert.Equal(t, template.HTML(test.expected), res, "Unexpected result in testcase %q", test.testcase)
}
})
}
func TestFootnote(t *testing.T) {