Skip to content

Commit

Permalink
Fix #27605: inline math blocks can't be preceeded/followed by alphanu…
Browse files Browse the repository at this point in the history
…merical characters

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 <[email protected]>
  • Loading branch information
jmlt2002 committed Mar 29, 2024
1 parent e40fc75 commit c75fa56
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 10 deletions.
4 changes: 2 additions & 2 deletions modules/markup/markdown/markdown_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -509,15 +509,15 @@ func TestMathBlock(t *testing.T) {
},
{
`$a a$b b$`,
`<p><code class="language-math is-loading">a a$b b</code></p>` + nl,
`<p><code class="language-math is-loading">a a</code>b b$</p>` + nl,
},
{
`a a$b b`,
`<p>a a$b b</p>` + nl,
},
{
`a$b $a a$b b$`,
`<p>a$b <code class="language-math is-loading">a a$b b</code></p>` + nl,
`<p>a<code class="language-math is-loading">b </code>a a<code class="language-math is-loading">b b</code></p>` + nl,
},
{
"$$a$$",
Expand Down
11 changes: 3 additions & 8 deletions modules/markup/markdown/math/inline_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)
}
Expand Down

0 comments on commit c75fa56

Please sign in to comment.