goessner / markdown-it-texmath

Support TeX math equations with your Markdown documents.
MIT License
156 stars 28 forks source link

fix the bracket and equation issue #11

Closed shi-yan closed 5 years ago

shi-yan commented 5 years ago

you have 2 regexps, one matches equations with an index on matches equations without an index,

xxxxxx (1)

or

xxxxxx

the code prioritize the first regexp over the second, then you have more than one lines of equations like:

aaaaa

.... some text ...

bbbbb (1)

Javascript tends to match the longest string possible, so it will treat the above as a single equation, hence the bug.

The fix adds a negative lookahead to exclude \[ \] patterns from an equation match. This will change the regexp capture index. so I also changed res[2] to res[res.length -1]