From 7fbcc58062c5cad5c4c8674915ea0fffa659b51d Mon Sep 17 00:00:00 2001 From: Giteabot Date: Thu, 20 Jun 2024 17:45:08 +0800 Subject: [PATCH] Fix markdown math brackets render problem (#31420) (#31430) Backport #31420 by charles7668 Co-authored-by: charles <30816317+charles7668@users.noreply.github.com> Co-authored-by: wxiaoguang --- modules/markup/markdown/markdown_test.go | 4 ++++ modules/markup/markdown/math/inline_parser.go | 6 +++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/modules/markup/markdown/markdown_test.go b/modules/markup/markdown/markdown_test.go index ecd747214b..d71ca36386 100644 --- a/modules/markup/markdown/markdown_test.go +++ b/modules/markup/markdown/markdown_test.go @@ -542,6 +542,10 @@ func TestMathBlock(t *testing.T) { "$$a$$", `
a
` + nl, }, + { + "$a$ ($b$) [$c$] {$d$}", + `

a (b) [$c$] {$d$}

` + nl, + }, } for _, test := range testcases { diff --git a/modules/markup/markdown/math/inline_parser.go b/modules/markup/markdown/math/inline_parser.go index 862234e69b..614cf329af 100644 --- a/modules/markup/markdown/math/inline_parser.go +++ b/modules/markup/markdown/math/inline_parser.go @@ -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] != '\\' { -- 2.39.5