Skip to content

Commit

Permalink
Fix slight bug in katex
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
zeripath committed Oct 4, 2022
1 parent 2d2cf58 commit 840d938
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions modules/markup/markdown/math/inline_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,20 +59,29 @@ func (parser *inlineParser) Parse(parent ast.Node, block text.Reader, pc parser.
}

opener += len(parser.start)
ender := bytes.Index(line[opener:], parser.end)
if ender < 0 {
return nil
}
if len(line) > opener+ender+len(parser.end) && isAlphanumeric(line[opener+ender+len(parser.end)]) {
return nil
ender := opener
for pos := opener; pos < len(line); {
ender = bytes.Index(line[pos:], parser.end)
if ender < 0 {
return nil
}

ender += pos
pos += len(parser.end)
if len(line) <= pos {
break
}
if !isAlphanumeric(line[pos]) {
break
}
}

block.Advance(opener)
_, pos := block.Position()
node := NewInline()
segment := pos.WithStop(pos.Start + ender)
segment := pos.WithStop(pos.Start + ender - opener)
node.AppendChild(node, ast.NewRawTextSegment(segment))
block.Advance(ender + len(parser.end))
block.Advance(ender - opener + len(parser.end))

trimBlock(node, block)
return node
Expand Down

0 comments on commit 840d938

Please sign in to comment.