From 41ccfce3e9c04f217c29aff7bfd7c3d434eb9149 Mon Sep 17 00:00:00 2001 From: Yunus Ozen <94426948+ozenyunus35@users.noreply.github.com> Date: Wed, 14 Oct 2026 22:11:13 +0300 Subject: [PATCH] fix(markup): parse \(...\) inline math next to letters and digits (#39773) Fixes https://github.com/go-gitea/gitea/issues/39770 `\(x^2\)is` and `\(x^2\)123` rendered as plain text because `\(...\)` went through the same check on surrounding characters as `$...$`. That check is there to skip things like `US$1`, which can't happen with explicit `\(` `\)` delimiters, so it's now skipped for them, the same as for "$`...`$". `$x$a` still isn't parsed. --- modules/markup/markdown/markdown_math_test.go | 4 ++++ modules/markup/markdown/math/inline_parser.go | 1 + 2 files changed, 5 insertions(+) diff --git a/modules/markup/markdown/markdown_math_test.go b/modules/markup/markdown/markdown_math_test.go index c96ab208db1..f2a64da9dfc 100644 --- a/modules/markup/markdown/markdown_math_test.go +++ b/modules/markup/markdown/markdown_math_test.go @@ -42,6 +42,10 @@ func TestMathRender(t *testing.T) { `\(a\) \(b\)`, `

a b

` + nl, }, + { + `\(x^2\)is \(x^2\)123 a\(b\)c`, + `

x^2is x^2123 abc

` + nl, + }, { `$a$.`, `

a.

` + nl, diff --git a/modules/markup/markdown/math/inline_parser.go b/modules/markup/markdown/math/inline_parser.go index 111e4038349..fe56d29137d 100644 --- a/modules/markup/markdown/math/inline_parser.go +++ b/modules/markup/markdown/math/inline_parser.go @@ -91,6 +91,7 @@ func (parser *inlineParser) Parse(parent ast.Node, block text.Reader, pc parser. } else { startMarkLen = 2 stopMark = parser.endBytesParentheses + checkSurrounding = false // explicit delimiters like "$`...`$", adjacent text is unambiguous } if line[0] == '$' && !parser.enableInlineDollar && (len(line) == 1 || line[1] != '`') {