Fixes markdown katex bug#1586
Conversation
|
Bugbot is not enabled for your account, so this pull request was not reviewed. Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 131fa24f0e
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3d4927dfbd
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const source = $span.text(); | ||
|
|
||
| $span.replaceWith(renderTex(source, display)); |
There was a problem hiding this comment.
Preserve escaped TeX when rendering fails
If a Pandoc math span contains invalid TeX with escaped markup, such as \bad <img src=x onerror=...>, this path decodes the entity via .text(), then renderTex falls back to returning $$ + original + $$, and replaceWith reparses that fallback as HTML. In that failure case escaped source text is turned into live tags instead of remaining a literal failed equation.
Useful? React with 👍 / 👎.
| } | ||
|
|
||
| function render($, callback) { | ||
| renderPandocMath($); |
There was a problem hiding this comment.
Skip newly rendered KaTeX spans during text scanning
When a Pandoc span contains valid TeX that itself includes a literal $$...$$ sequence, such as \text{$$x$$}, this runs before the later eachTextNode pass. Because that pass does not skip the .katex markup just inserted, it scans the MathML <annotation> text and treats the literal dollars as another equation, nesting KaTeX HTML inside the annotation and corrupting the rendered math.
Useful? React with 👍 / 👎.
| } | ||
|
|
||
| function renderPandocMath($) { | ||
| $("span.math.inline, span.math.display").each(function () { |
There was a problem hiding this comment.
Avoid re-rendering non-KaTeX Pandoc math spans
For files that reach this plugin from Pandoc converters other than the Markdown converter, the converter args still don't include --katex (for example app/build/converters/org/convert.js), so span.math contains Pandoc's plain/Unicode HTML rather than raw TeX. This selector nevertheless feeds the span text back to KaTeX, which reinterprets already-rendered output such as a fraction as 1/2 and loses the original formula.
Useful? React with 👍 / 👎.
There was previously an issue handling katex blocks with markdown inside, e.g.
Would become:
This is now fixed.
This is an inline <code>$$withmath$$</code>