Skip to content

Commit 88f41f3

Browse files
committed
Allow math expressions to be preceeded but not suceeded by alphanumerical characters
Signed-off-by: João Tiago <joao.leal.tintas@tecnico.ulisboa.pt>
1 parent e375bf3 commit 88f41f3

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

modules/markup/markdown/markdown_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -509,23 +509,23 @@ func TestMathBlock(t *testing.T) {
509509
},
510510
{
511511
`$a a$b b$`,
512-
`<p><code class="language-math is-loading">a a</code>b b$</p>` + nl,
512+
`<p>$a a<code class="language-math is-loading">b b</code></p>` + nl,
513513
},
514514
{
515515
`a a$b b`,
516516
`<p>a a$b b</p>` + nl,
517517
},
518518
{
519519
`a$b $a a$b b$`,
520-
`<p>a<code class="language-math is-loading">b </code>a a<code class="language-math is-loading">b b</code></p>` + nl,
520+
`<p>a$b $a a<code class="language-math is-loading">b b</code></p>` + nl,
521521
},
522522
{
523523
"a$x$",
524524
`<p>a<code class="language-math is-loading">x</code></p>` + nl,
525525
},
526526
{
527527
"$x$a",
528-
`<p><code class="language-math is-loading">x</code>a</p>` + nl,
528+
`<p>$x$a</p>` + nl,
529529
},
530530
{
531531
"$$a$$",

modules/markup/markdown/math/inline_parser.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ func (parser *inlineParser) Trigger() []byte {
4141
return parser.start[0:1]
4242
}
4343

44+
func isAlphanumeric(b byte) bool {
45+
// Github only cares about 0-9A-Za-z
46+
return (b >= '0' && b <= '9') || (b >= 'A' && b <= 'Z') || (b >= 'a' && b <= 'z')
47+
}
48+
4449
// Parse parses the current line and returns a result of parsing.
4550
func (parser *inlineParser) Parse(parent ast.Node, block text.Reader, pc parser.Context) ast.Node {
4651
line, _ := block.PeekLine()
@@ -69,6 +74,9 @@ func (parser *inlineParser) Parse(parent ast.Node, block text.Reader, pc parser.
6974
if len(line) <= pos {
7075
break
7176
}
77+
if isAlphanumeric(line[pos]) {
78+
return nil
79+
}
7280
if line[ender-1] != '\\' {
7381
break
7482
}

0 commit comments

Comments
 (0)