Skip to content

Commit

Permalink
Fix markdown math brackets render problem (go-gitea#31420)
Browse files Browse the repository at this point in the history
Close go-gitea#31371, support `($ ... $)` like GitHub

Co-authored-by: wxiaoguang <[email protected]>
  • Loading branch information
charles7668 and wxiaoguang authored Jun 20, 2024
1 parent 1c15452 commit 90a3c20
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 4 additions & 0 deletions modules/markup/markdown/markdown_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 5 additions & 1 deletion modules/markup/markdown/math/inline_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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')
}
Expand Down Expand Up @@ -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] != '\\' {
Expand Down

0 comments on commit 90a3c20

Please sign in to comment.