Skip to content

Commit 840d938

Browse files
committed
Fix slight bug in katex
There is a small bug in go-gitea#20571 whereby `$a a$b b$` will not be correctly detected as a math inline block of `a a$b b`. This PR fixes this. Signed-off-by: Andrew Thornton <art27@cantab.net>
1 parent 2d2cf58 commit 840d938

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

modules/markup/markdown/math/inline_parser.go

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,20 +59,29 @@ func (parser *inlineParser) Parse(parent ast.Node, block text.Reader, pc parser.
5959
}
6060

6161
opener += len(parser.start)
62-
ender := bytes.Index(line[opener:], parser.end)
63-
if ender < 0 {
64-
return nil
65-
}
66-
if len(line) > opener+ender+len(parser.end) && isAlphanumeric(line[opener+ender+len(parser.end)]) {
67-
return nil
62+
ender := opener
63+
for pos := opener; pos < len(line); {
64+
ender = bytes.Index(line[pos:], parser.end)
65+
if ender < 0 {
66+
return nil
67+
}
68+
69+
ender += pos
70+
pos += len(parser.end)
71+
if len(line) <= pos {
72+
break
73+
}
74+
if !isAlphanumeric(line[pos]) {
75+
break
76+
}
6877
}
6978

7079
block.Advance(opener)
7180
_, pos := block.Position()
7281
node := NewInline()
73-
segment := pos.WithStop(pos.Start + ender)
82+
segment := pos.WithStop(pos.Start + ender - opener)
7483
node.AppendChild(node, ast.NewRawTextSegment(segment))
75-
block.Advance(ender + len(parser.end))
84+
block.Advance(ender - opener + len(parser.end))
7685

7786
trimBlock(node, block)
7887
return node

0 commit comments

Comments
 (0)