Skip to content

Commit 7fbcc58

Browse files
GiteaBotcharles7668wxiaoguang
authored
Fix markdown math brackets render problem (#31420) (#31430)
Backport #31420 by charles7668 Co-authored-by: charles <[email protected]> Co-authored-by: wxiaoguang <[email protected]>
1 parent 05f3211 commit 7fbcc58

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

modules/markup/markdown/markdown_test.go

Lines changed: 4 additions & 0 deletions
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

Lines changed: 5 additions & 1 deletion
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)