Skip to content

Commit 7f52413

Browse files
committed
fix: inline math blocks can't be preceeded/followed by alphanumerical 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 <[email protected]>
1 parent e40fc75 commit 7f52413

File tree

2 files changed

+5
-10
lines changed

2 files changed

+5
-10
lines changed

modules/markup/markdown/markdown_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -509,15 +509,15 @@ func TestMathBlock(t *testing.T) {
509509
},
510510
{
511511
`$a a$b b$`,
512-
`<p><code class="language-math is-loading">a a$b b</code></p>` + nl,
512+
`<p><code class="language-math is-loading">a a</code>b b$</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$b <code class="language-math is-loading">a a$b b</code></p>` + nl,
520+
`<p>a<code class="language-math is-loading">b </code>a a<code class="language-math is-loading">b b</code></p>` + nl,
521521
},
522522
{
523523
"$$a$$",

modules/markup/markdown/math/inline_parser.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,6 @@ func (parser *inlineParser) Parse(parent ast.Node, block text.Reader, pc parser.
5555
return nil
5656
}
5757

58-
precedingCharacter := block.PrecendingCharacter()
59-
if precedingCharacter < 256 && isAlphanumeric(byte(precedingCharacter)) {
60-
// need to exclude things like `a$` from being considered a start
61-
return nil
62-
}
63-
6458
// move the opener marker point at the start of the text
6559
opener := len(parser.start)
6660

@@ -75,14 +69,15 @@ func (parser *inlineParser) Parse(parent ast.Node, block text.Reader, pc parser.
7569
ender += pos
7670

7771
// Now we want to check the character at the end of our parser section
78-
// that is ender + len(parser.end)
72+
// that is ender + len(parser.end) and check if char before ender is '\' && char before ender -2 is '\\'
7973
pos = ender + len(parser.end)
8074
if len(line) <= pos {
8175
break
8276
}
83-
if !isAlphanumeric(line[pos]) {
77+
if line[ender-1] != '\\' {
8478
break
8579
}
80+
8681
// move the pointer onwards
8782
ender += len(parser.end)
8883
}

0 commit comments

Comments
 (0)