Skip to content

Commit 2c650bc

Browse files
committed
Fix markdown math brackets render problem (#31371)
1 parent 7adf8d7 commit 2c650bc

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
@@ -551,6 +551,10 @@ func TestMathBlock(t *testing.T) {
551551
"$$a$$",
552552
`<pre class="code-block is-loading"><code class="chroma language-math display">a</code></pre>` + nl,
553553
},
554+
{
555+
"$a$ ($b$) [$c$] {$d$}",
556+
`<p><code class="language-math is-loading">a</code> (<code class="language-math is-loading">b</code>) [<code class="language-math is-loading">c</code>] {<code class="language-math is-loading">d</code>}</p>` + nl,
557+
},
554558
}
555559

556560
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 == '(' || b == ')' || b == '[' || b == ']' || b == '{' || 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)