fix(markdown): avoid parsing currency as LaTeX - #1997
Conversation
|
Caution The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased. |
📝 WalkthroughWalkthroughLaTeX 插件将美元公式匹配与括号定界匹配拆分,并增加单美元定界合法性校验;测试覆盖货币文本、数字开头公式及空白或相邻字符导致的无效定界场景。 ChangesLaTeX 解析规则
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Bundle ReportChanges will increase total bundle size by 8 bytes (0.0%) ⬆️. This is within the configured threshold ✅ Detailed changes
Affected Assets, Files, and Routes:view changes for bundle: antdx-array-pushAssets Changed:
|
|
This comment is automatically generated by the x-markdown performance CI. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1997 +/- ##
=======================================
Coverage 97.06% 97.07%
=======================================
Files 159 159
Lines 5766 5774 +8
Branches 1713 1715 +2
=======================================
+ Hits 5597 5605 +8
Misses 167 167
Partials 2 2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Deploying ant-design-x with
|
| Latest commit: |
46ae60f
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://fdce1869.ant-design-x.pages.dev |
| Branch Preview URL: | https://codex-fix-x-markdown-latex-c.ant-design-x.pages.dev |
size-limit report 📦
|
|
Caution The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased. |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/x-markdown/src/plugins/Latex/index.ts`:
- Line 6: Update inlineDollarRule to recognize escaped dollar signs within LaTeX
content, so sequences such as \${} are not treated as closing delimiters;
preserve the existing single- and double-dollar delimiter handling and length
limit, and add a regression test covering $\text{\$100}$.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 06c91106-05ec-4050-af4a-0fc267bfb5b9
📒 Files selected for processing (2)
packages/x-markdown/src/plugins/Latex/__tests__/index.test.tsxpackages/x-markdown/src/plugins/Latex/index.ts
|
|
||
| const inlineRuleNonStandard = | ||
| /^(?:\${1,2}([^$]{1,10000}?)\${1,2}|\\\(([\s\S]{1,10000}?)\\\)|\\\[((?:\\.|[^\\]){1,10000}?)\\\])/; | ||
| const inlineDollarRule = /^(\${1,2})([^$]{1,10000}?)\1/; |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
支持公式内容中的转义美元符。
[^$] 会把 $\text{\$100}$ 中的 \$ 误当作关闭定界符,导致公式被截断并产生 KaTeX 解析错误。允许反斜杠转义的字符,并补充该回归用例。
建议修改
-const inlineDollarRule = /^(\${1,2})([^$]{1,10000}?)\1/;
+const inlineDollarRule = /^(\${1,2})((?:\\[\s\S]|[^$]){1,10000}?)\1/;📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| const inlineDollarRule = /^(\${1,2})([^$]{1,10000}?)\1/; | |
| const inlineDollarRule = /^(\${1,2})((?:\\[\s\S]|[^$]){1,10000}?)\1/; |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@packages/x-markdown/src/plugins/Latex/index.ts` at line 6, Update
inlineDollarRule to recognize escaped dollar signs within LaTeX content, so
sequences such as \${} are not treated as closing delimiters; preserve the
existing single- and double-dollar delimiter handling and length limit, and add
a regression test covering $\text{\$100}$.
🤔 This is a ...
🔗 Related Issues
No existing issue or pull request matched this bug.
💡 Background and Solution
The built-in
x-markdownLaTeX tokenizer currently treats any text between two$characters as math. Prose containing multiple currency amounts, such asDowngrade Max ($100) to Pro ($20), is therefore rendered as KaTeX. CJK prose also causes repeatedunicodeTextInMathModewarnings because natural-language text is passed into KaTeX math mode.This change:
\(...\)and\[...\]parsing;$/$$delimiter lengths;$;$2x + 1$and all existing double-dollar behavior;Validation:
npm exec --workspace packages/x-markdown -- jest --config .jest.js --runInBand --no-cache— 7 suites, 338 tests, 28 snapshots passed.npm run tsc --workspace packages/x-markdown— passed.npm exec --workspace packages/x-markdown -- biome check src/plugins/Latex/index.ts src/plugins/Latex/__tests__/index.test.tsx— passed.biome lintremains blocked by two pre-existingnoDangerouslySetInnerHtmlerrors in benchmark-onlyMarkdownRenderer.tsx; neither file is touched by this PR.Reference: Pandoc's
tex_math_dollarsdelimiter rules: https://pandoc.org/demo/example26.html📝 Change Log
Summary by CodeRabbit
$2x + 1$。