aboutsummaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
authorcharles <30816317+charles7668@users.noreply.github.com>2024-06-20 10:12:54 +0800
committerGitHub <noreply@github.com>2024-06-20 02:12:54 +0000
commit90a3c20e7996e2db577a51d37f2190e2e990a22a (patch)
tree8650716a2bb18fbca7648240e15a500eb0b3b4c3 /modules
parent1c1545268743d7d4536a5ff2a137af7c255f45c8 (diff)
downloadgitea-90a3c20e7996e2db577a51d37f2190e2e990a22a.tar.gz
gitea-90a3c20e7996e2db577a51d37f2190e2e990a22a.zip
Fix markdown math brackets render problem (#31420)
Close #31371, support `($ ... $)` like GitHub Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
Diffstat (limited to 'modules')
-rw-r--r--modules/markup/markdown/markdown_test.go4
-rw-r--r--modules/markup/markdown/math/inline_parser.go6
2 files changed, 9 insertions, 1 deletions
diff --git a/modules/markup/markdown/markdown_test.go b/modules/markup/markdown/markdown_test.go
index 9a8c39df0a..1a88d5d44a 100644
--- a/modules/markup/markdown/markdown_test.go
+++ b/modules/markup/markdown/markdown_test.go
@@ -551,6 +551,10 @@ func TestMathBlock(t *testing.T) {
"$$a$$",
`<pre class="code-block is-loading"><code class="chroma language-math display">a</code></pre>` + nl,
},
+ {
+ "$a$ ($b$) [$c$] {$d$}",
+ `<p><code class="language-math is-loading">a</code> (<code class="language-math is-loading">b</code>) [$c$] {$d$}</p>` + nl,
+ },
}
for _, test := range testcases {
diff --git a/modules/markup/markdown/math/inline_parser.go b/modules/markup/markdown/math/inline_parser.go
index 862234e69b..614cf329af 100644
--- a/modules/markup/markdown/math/inline_parser.go
+++ b/modules/markup/markdown/math/inline_parser.go
@@ -45,6 +45,10 @@ func isPunctuation(b byte) bool {
return b == '.' || b == '!' || b == '?' || b == ',' || b == ';' || b == ':'
}
+func isBracket(b byte) bool {
+ return b == ')'
+}
+
func isAlphanumeric(b byte) bool {
return (b >= 'a' && b <= 'z') || (b >= 'A' && b <= 'Z') || (b >= '0' && b <= '9')
}
@@ -84,7 +88,7 @@ func (parser *inlineParser) Parse(parent ast.Node, block text.Reader, pc parser.
break
}
suceedingCharacter := line[pos]
- if !isPunctuation(suceedingCharacter) && !(suceedingCharacter == ' ') {
+ if !isPunctuation(suceedingCharacter) && !(suceedingCharacter == ' ') && !isBracket(suceedingCharacter) {
return nil
}
if line[ender-1] != '\\' {