diff --git a/modules/markup/markdown/markdown_test.go b/modules/markup/markdown/markdown_test.go index 808c7c4e69b57..bfc44728d4fa3 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$
$a ab b
ab
a ab b
a$b $a ab b
x
a
$x$a
` + nl, }, { "$$a$$", diff --git a/modules/markup/markdown/math/inline_parser.go b/modules/markup/markdown/math/inline_parser.go index 42c4996668bc5..09fcd45ffdbd1 100644 --- a/modules/markup/markdown/math/inline_parser.go +++ b/modules/markup/markdown/math/inline_parser.go @@ -41,6 +41,11 @@ func (parser *inlineParser) Trigger() []byte { return parser.start[0:1] } +func isAlphanumeric(b byte) bool { + // Github only cares about 0-9A-Za-z + return (b >= '0' && b <= '9') || (b >= 'A' && b <= 'Z') || (b >= 'a' && b <= 'z') +} + // 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() @@ -69,6 +74,9 @@ func (parser *inlineParser) Parse(parent ast.Node, block text.Reader, pc parser. if len(line) <= pos { break } + if isAlphanumeric(line[pos]) { + return nil + } if line[ender-1] != '\\' { break }