fix: protect special characters in math from markdown table parsers (#1462)#8000
Open
hugogu wants to merge 3 commits into
Open
fix: protect special characters in math from markdown table parsers (#1462)#8000hugogu wants to merge 3 commits into
hugogu wants to merge 3 commits into
Conversation
Wiki.js uses markdown-it-attrs which interprets curly braces inside
inline math ($...$) as attribute directives, stripping them from the
formula. Additionally, markdown table parsers split cells at both `|`
and `&` characters, breaking formulas containing those symbols.
This fix replaces `{`, `}`, `|`, and `&` inside math expressions with
Unicode Private Use Area placeholders during markdown parsing, then
restores them before passing to KaTeX/MathJax for rendering.
- `<E000>` / `<E001>`: temporary replacements for `{` / `}`
- `<E002>`: temporary replacement for `|` (table cell delimiter)
- `<E003>`: temporary replacement for `&` (table cell delimiter in
multiline tables, used by LaTeX cases/arrays)
The placeholder approach was chosen over HTML escaping because it
preserves LaTeX environments like `\begin{array}` that were broken
by the previous `{{}}` escaping method.
Fixes requarks#1581
Fixes requarks#1462
Co-authored-by: Claude <noreply@anthropic.com>
AI-model: kimi-for-coding/k2p6
Unclosed $ delimiters would span across multiple lines, causing protectMathPipes() to corrupt table cell delimiters in unrelated content. Limit inline math matching to the same line to prevent false matches. Co-authored-by: Claude <noreply@anthropic.com> AI-model: kimi-for-coding/k2p6
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Change Summary
Wiki.js uses markdown-it-attrs which interprets curly braces inside inline math ($...$ ) as attribute directives, stripping them from the formula. Additionally, markdown table parsers split cells at both
|and&characters, breaking formulas containing those symbols.This fix replaces
{,},|, and&inside math expressions with Unicode Private Use Area placeholders during markdown parsing, then restores them before passing to KaTeX/MathJax for rendering.<E000>/<E001>: temporary replacements for{/}<E002>: temporary replacement for|(table cell delimiter)<E003>: temporary replacement for&(table cell delimiter in multiline tables, used by LaTeX cases/arrays)The placeholder approach was chosen over HTML escaping because it preserves LaTeX environments like
\begin{array}that were broken by the previous{{}}escaping method.Fixes #1581
Fixes #1462
Test
The latest build by now (2.5.314) render it as

and
After the fix all latex text will be rendered correctly:
and