From 50b6d4e93f1c609200b2bf9ea54cbbbb964338d2 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Wed, 10 Dec 2025 16:04:03 +0800 Subject: [PATCH 1/2] fix --- modules/markup/markdown/markdown_math_test.go | 10 +++++++++- modules/markup/markdown/math/inline_parser.go | 10 +++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/modules/markup/markdown/markdown_math_test.go b/modules/markup/markdown/markdown_math_test.go index a75f18d36a843..9e368cb689a3a 100644 --- a/modules/markup/markdown/markdown_math_test.go +++ b/modules/markup/markdown/markdown_math_test.go @@ -30,6 +30,10 @@ func TestMathRender(t *testing.T) { "$ a $", `

a

` + nl, }, + { + "$a$$b$", + `

ab

` + nl, + }, { "$a$ $b$", `

a b

` + nl, @@ -59,7 +63,7 @@ func TestMathRender(t *testing.T) { `

a$b $a a$b b$

` + nl, }, { - "a$x$", + "a$x$", // Pattern: "word$other$" The real world example is: "Price is between US$1 and US$2.", so don't parse this. `

a$x$

` + nl, }, { @@ -70,6 +74,10 @@ func TestMathRender(t *testing.T) { "$a$ ($b$) [$c$] {$d$}", `

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

` + nl, }, + { + "[$a$](link)", + `

a

` + nl, + }, { "$$a$$", `

a

` + nl, diff --git a/modules/markup/markdown/math/inline_parser.go b/modules/markup/markdown/math/inline_parser.go index a711d1e1cd1d7..971cdcc2a2983 100644 --- a/modules/markup/markdown/math/inline_parser.go +++ b/modules/markup/markdown/math/inline_parser.go @@ -54,6 +54,12 @@ func isAlphanumeric(b byte) bool { return (b >= 'a' && b <= 'z') || (b >= 'A' && b <= 'Z') || (b >= '0' && b <= '9') } +func isInMarkdownLinkText(block text.Reader, lineAfter []byte) bool { + src := block.Source() + _, pos := block.Position() + return pos.Start-1 >= 0 && src[pos.Start-1] == '[' && bytes.HasPrefix(lineAfter, []byte("](")) +} + // Parse parses the current line and returns a result of parsing. func (parser *inlineParser) Parse(parent ast.Node, block text.Reader, pc parser.Context) ast.Node { line, _ := block.PeekLine() @@ -115,7 +121,9 @@ func (parser *inlineParser) Parse(parent ast.Node, block text.Reader, pc parser. } // check valid ending character isValidEndingChar := isPunctuation(succeedingCharacter) || isParenthesesClose(succeedingCharacter) || - succeedingCharacter == ' ' || succeedingCharacter == '\n' || succeedingCharacter == 0 + succeedingCharacter == ' ' || succeedingCharacter == '\n' || succeedingCharacter == 0 || + succeedingCharacter == '$' || + isInMarkdownLinkText(block, line[i+len(stopMark):]) if checkSurrounding && !isValidEndingChar { break } From e931e6cf9532aa5ec85c80da848b398beff6ba7c Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Wed, 10 Dec 2025 17:10:27 +0800 Subject: [PATCH 2/2] simplify --- modules/markup/markdown/math/inline_parser.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/modules/markup/markdown/math/inline_parser.go b/modules/markup/markdown/math/inline_parser.go index 971cdcc2a2983..564861df90ba8 100644 --- a/modules/markup/markdown/math/inline_parser.go +++ b/modules/markup/markdown/math/inline_parser.go @@ -55,9 +55,7 @@ func isAlphanumeric(b byte) bool { } func isInMarkdownLinkText(block text.Reader, lineAfter []byte) bool { - src := block.Source() - _, pos := block.Position() - return pos.Start-1 >= 0 && src[pos.Start-1] == '[' && bytes.HasPrefix(lineAfter, []byte("](")) + return block.PrecendingCharacter() == '[' && bytes.HasPrefix(lineAfter, []byte("](")) } // Parse parses the current line and returns a result of parsing.