mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-14 05:01:13 +00:00
Fix markdown math brackets render problem (#31420)
Close #31371, support `($ ... $)` like GitHub Co-authored-by: wxiaoguang <wxiaoguang@gmail.com> (cherry picked from commit 90a3c20e7996e2db577a51d37f2190e2e990a22a) Conflicts: modules/markup/markdown/markdown_test.go trivial context conflict
This commit is contained in:
parent
4ebe8c1270
commit
b53be9d45c
2 changed files with 9 additions and 1 deletions
|
@ -548,6 +548,10 @@ func TestMathBlock(t *testing.T) {
|
|||
`$$a`,
|
||||
`<p>$$a</p>` + 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 {
|
||||
|
|
|
@ -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] != '\\' {
|
||||
|
|
Loading…
Reference in a new issue