Recognise $$ display math and \( \) inline math - #55
Merged
Conversation
Adds MarkdownMathBlockNode/MarkdownMathInlineNode to the AST, block/inline parser support, and lowering into ContentDocument as preserved literal LaTeX text (styleId "MathBlock" for the block form, a dedicated ContentRun.fontFamily marker for the inline form), with a full write-side inverse in src/emit. Converting the preserved LaTeX to real MathML is out of scope here -- that is a documents.js question (ExaDev/documents.js#563). Fixes the reported bug where \( \) was silently read as an escaped literal '(' and ')', eating the delimiters. As part of this, '(' and ')' are removed from escapeMarkdownText's own ESCAPE_CHARS: escaping them was always unnecessary (neither carries special meaning in ordinary running text under CommonMark's grammar), and once \( \) means something, keeping them escaped would manufacture the same shape out of any ordinary parenthetical remark and misread it as math on a later reparse. Closes #53.
Contributor
|
🎉 This PR is included in version 1.4.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
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.
Summary
MarkdownMathBlockNode($$...$$) andMarkdownMathInlineNode(\(...\)) to the AST, with block/inline parser support and lowering intoContentDocumentas preserved literal LaTeX text —styleId: "MathBlock"for the block form, a dedicatedContentRun.fontFamilymarker (Cambria Math) for the inline form, mirroring how a code span already usesCourier New. Full write-side inverse insrc/emit.\(...\)was silently read as an escaped literal(and), eating the delimiters.(and)are removed fromescapeMarkdownText's ownESCAPE_CHARS: escaping them was always unnecessary (neither carries special meaning in ordinary running text under CommonMark's grammar), and once\( \)means something, keeping them escaped would manufacture the same shape out of any ordinary parenthetical remark and misread it as math on a later reparse. Verified via the full CommonMark/GFM conformance suite — only one genuinely irreducible divergence surfaced (a synthetic "escape every punctuation character" torture-test example), added to the shrink-only exclusion list with its own named reason.Closes #53.
Test plan
pnpm typecheckpnpm lintpnpm test— 939 tests passing, including new coverage for math block/inline parsing, lowering, emit, and diagnostics reachabilitypnpm test:workerspnpm test:smokeGenerated by Claude Code