From 0423e0ea6735b8d2dc14f43d3fcb304861c130d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Tiago?= Date: Thu, 28 Mar 2024 18:41:55 +0000 Subject: [PATCH] Fix #27605: inline math blocks can't be preceeded/followed by alphanumerical characters MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Inline math blocks couldn't be preceeded or succeeded by alphanumerical characters due to changes introduced in PR #21171. Removed the condition that caused this (precedingCharacter) and added a new if statement that checks if a specific '$' was escaped using '\'. Signed-off-by: João Tiago --- modules/markup/markdown/markdown_test.go | 4 ++-- modules/markup/markdown/math/inline_parser.go | 11 +++-------- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/modules/markup/markdown/markdown_test.go b/modules/markup/markdown/markdown_test.go index ebac3fbe9e8e0..cddfb0c85166d 100644 --- a/modules/markup/markdown/markdown_test.go +++ b/modules/markup/markdown/markdown_test.go @@ -509,7 +509,7 @@ func TestMathBlock(t *testing.T) { }, { `$a a$b b$`, - `

a a$b b

` + nl, + `

a ab b$

` + nl, }, { `a a$b b`, @@ -517,7 +517,7 @@ func TestMathBlock(t *testing.T) { }, { `a$b $a a$b b$`, - `

a$b a a$b b

` + nl, + `

ab a ab b

` + nl, }, { "$$a$$", diff --git a/modules/markup/markdown/math/inline_parser.go b/modules/markup/markdown/math/inline_parser.go index 0ac25c2b2ac86..ec49b4b24f7e0 100644 --- a/modules/markup/markdown/math/inline_parser.go +++ b/modules/markup/markdown/math/inline_parser.go @@ -55,12 +55,6 @@ func (parser *inlineParser) Parse(parent ast.Node, block text.Reader, pc parser. return nil } - precedingCharacter := block.PrecendingCharacter() - if precedingCharacter < 256 && isAlphanumeric(byte(precedingCharacter)) { - // need to exclude things like `a$` from being considered a start - return nil - } - // move the opener marker point at the start of the text opener := len(parser.start) @@ -75,14 +69,15 @@ func (parser *inlineParser) Parse(parent ast.Node, block text.Reader, pc parser. ender += pos // Now we want to check the character at the end of our parser section - // that is ender + len(parser.end) + // that is ender + len(parser.end) and check if char before ender is '\' pos = ender + len(parser.end) if len(line) <= pos { break } - if !isAlphanumeric(line[pos]) { + if line[ender-1] != '\\' { break } + // move the pointer onwards ender += len(parser.end) }