Skip to content

Commit

Permalink
fix: inline math blocks can't be preceeded/followed by alphanumerical…
Browse files Browse the repository at this point in the history
… characters

Fixes issue go-gitea#27605, changed tests to account for these changes. This bug happened because of the changes introduced in PR go-gitea#21171.

Signed-off-by: João Tiago <joao.leal.tintas@tecnico.ulisboa.pt>
  • Loading branch information
jmlt2002 committed Mar 28, 2024
1 parent e40fc75 commit 7f52413
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 '\' && char before ender -2 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 7f52413

Please sign in to comment.