denoland / deno-gfm

Server-side GitHub Flavored Markdown rendering for Deno
https://jsr.io/@deno/gfm
MIT License
221 stars 33 forks source link

bug fix: inline math #42

Closed KorigamiK closed 1 year ago

KorigamiK commented 1 year ago

The PR fixes a bug where Katex would error out if the content in an inline math block would have length less than 3.

For example: Consider the following markdown snippet,

This letter is typeset inline $x$. This is another inline math block $Quadratic \; Formula$.

This causes this error upon rendering:

KaTeX parse error: Can't use function '$' in math mode at position 2: x$̲. This is anoth…

Because the original regex /\s\$(\S.+?\S)\$/ assumes that the content is non-empty, it is prefixed and suffixed by a necessary non-whitespace character.

The new regex /\s\$((?=\S).*?(?=\S))\$/ takes care of this error by having positive lookup at the start and the end of the content.