fix: inline math interpreted as attributes #2645
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When using inline math (
$e^{-x^2}$
) the curly braces are interpreted as attributes by markdown-it-attrs. Since most of the times they are not valid attributes they simply get removed.This patch escapes the curly braces (the default attribute delimiter), fixing the KaTeX rendering errors.
The problem occurs only when the inline math ends with a curly brace block (see examples below). For this reason the third example below works also in the current version.
An alternative fix may have been to force the math block not to end with the curly braces, for example by adding some spacing (e.g.
\,
). I preferred not adding some spurious spaces, the escaping strategy should be pretty invisible.One could think it should be enough to escape the last
{
and}
, in practice it's not enough:$e^{e^{x}+1}$
would become$e^{e^{{x}+1}}$
, which is valid but clearly not equivalent. (note that this example is not broken in the current version since the last curly block contains another curly block, which apparently it's fine).It would be nice to simply skip that rule for
katex_inline
block types but as far as I know markdown-it-attrs doesn't have such an option.Example
Previously
Now
Fixes #1581