Skip to content

Commit ad4d1fa

Browse files
charles7668wxiaoguang
authored andcommitted
Fix markdown math brackets render problem (go-gitea#31420)
Close go-gitea#31371, support `($ ... $)` like GitHub Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
1 parent 05f3211 commit ad4d1fa

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

modules/markup/markdown/markdown_test.go

+4
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,10 @@ func TestMathBlock(t *testing.T) {
542542
"$$a$$",
543543
`<pre class="code-block is-loading"><code class="chroma language-math display">a</code></pre>` + nl,
544544
},
545+
{
546+
"$a$ ($b$) [$c$] {$d$}",
547+
`<p><code class="language-math is-loading">a</code> (<code class="language-math is-loading">b</code>) [$c$] {$d$}</p>` + nl,
548+
},
545549
}
546550

547551
for _, test := range testcases {

modules/markup/markdown/math/inline_parser.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ func isPunctuation(b byte) bool {
4545
return b == '.' || b == '!' || b == '?' || b == ',' || b == ';' || b == ':'
4646
}
4747

48+
func isBracket(b byte) bool {
49+
return b == ')'
50+
}
51+
4852
func isAlphanumeric(b byte) bool {
4953
return (b >= 'a' && b <= 'z') || (b >= 'A' && b <= 'Z') || (b >= '0' && b <= '9')
5054
}
@@ -84,7 +88,7 @@ func (parser *inlineParser) Parse(parent ast.Node, block text.Reader, pc parser.
8488
break
8589
}
8690
suceedingCharacter := line[pos]
87-
if !isPunctuation(suceedingCharacter) && !(suceedingCharacter == ' ') {
91+
if !isPunctuation(suceedingCharacter) && !(suceedingCharacter == ' ') && !isBracket(suceedingCharacter) {
8892
return nil
8993
}
9094
if line[ender-1] != '\\' {

0 commit comments

Comments
 (0)