Skip to content

Commit 1edf43a

Browse files
committed
Fix #27605: inline math blocks can't be preceeded/followed by alphanumerical 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]>
1 parent e40fc75 commit 1edf43a

File tree

2 files changed

+5
-15
lines changed

2 files changed

+5
-15
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 & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,6 @@ 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-
4944
// Parse parses the current line and returns a result of parsing.
5045
func (parser *inlineParser) Parse(parent ast.Node, block text.Reader, pc parser.Context) ast.Node {
5146
line, _ := block.PeekLine()
@@ -55,12 +50,6 @@ func (parser *inlineParser) Parse(parent ast.Node, block text.Reader, pc parser.
5550
return nil
5651
}
5752

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-
6453
// move the opener marker point at the start of the text
6554
opener := len(parser.start)
6655

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

7766
// Now we want to check the character at the end of our parser section
78-
// that is ender + len(parser.end)
67+
// that is ender + len(parser.end) and check if char before ender is '\'
7968
pos = ender + len(parser.end)
8069
if len(line) <= pos {
8170
break
8271
}
83-
if !isAlphanumeric(line[pos]) {
72+
if line[ender-1] != '\\' {
8473
break
8574
}
75+
8676
// move the pointer onwards
8777
ender += len(parser.end)
8878
}

0 commit comments

Comments
 (0)