Skip to content

Commit

Permalink
Allow math expressions to be preceeded but not suceeded by alphanumer…
Browse files Browse the repository at this point in the history
…ical characters

Signed-off-by: João Tiago <joao.leal.tintas@tecnico.ulisboa.pt>
  • Loading branch information
jmlt2002 committed Mar 31, 2024
1 parent e375bf3 commit 88f41f3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
6 changes: 3 additions & 3 deletions modules/markup/markdown/markdown_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -509,23 +509,23 @@ func TestMathBlock(t *testing.T) {
},
{
`$a a$b b$`,
`<p><code class="language-math is-loading">a a</code>b b$</p>` + nl,
`<p>$a a<code class="language-math is-loading">b b</code></p>` + nl,
},
{
`a a$b b`,
`<p>a a$b b</p>` + nl,
},
{
`a$b $a a$b b$`,
`<p>a<code class="language-math is-loading">b </code>a a<code class="language-math is-loading">b b</code></p>` + nl,
`<p>a$b $a a<code class="language-math is-loading">b b</code></p>` + nl,
},
{
"a$x$",
`<p>a<code class="language-math is-loading">x</code></p>` + nl,
},
{
"$x$a",
`<p><code class="language-math is-loading">x</code>a</p>` + nl,
`<p>$x$a</p>` + nl,
},
{
"$$a$$",
Expand Down
8 changes: 8 additions & 0 deletions modules/markup/markdown/math/inline_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 88f41f3

Please sign in to comment.