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 a
b 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)
}