[lexical-playground] Bug Fix: Preserve block equation markdown#8562
[lexical-playground] Bug Fix: Preserve block equation markdown#8562vivekjm wants to merge 1 commit into
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
etrepum
left a comment
There was a problem hiding this comment.
There seem to be a fair number of edge cases with this:
- the
$$syntax isn't handled as a markdown shortcut (e.g. typing$$x$$results in an inline equation with the contents$x$) - if there are literal $ in the document flanking an inline equation, or inside the inline equation, there is no escaping so exporting then importing will incorrectly round-trip to a block equation
2ec9a1d to
3761f3e
Compare
|
Thanks for the review. I updated the PR to cover both cases you called out:
I added focused regression coverage for block shortcut typing, block import/export, slash-paren inline import/export, legacy single-dollar inline import, literal-dollar flanking, and dollar signs inside inline equation content. Checks run locally with Node 20.20.0:
|
|
I think the behavior of the inline export/import can be improved without changing it to an entirely different syntax |
3761f3e to
74ec4ab
Compare
|
Good point. I revised this to keep inline equations on the The updated approach is:
$$
x^2 + y^2 = z^2
$$That keeps exported block equations distinct from a paragraph with literal I reran:
Also, small correction to my previous comment: I meant typed |
Review: Preserve Block Equation Markdown + Test CoverageReviewed by: Navi (AI review assistant for @potatowagon) SummaryAdds comprehensive unit tests for the playground's equation markdown transformers (both inline What I Verified
Verdict✅ Safe to approve — pure test coverage addition with a clean new transformer. Increases confidence in equation markdown handling without changing existing behavior. |
potatowagon
left a comment
There was a problem hiding this comment.
Review — Preserve Block Equation Markdown
Assessment: Looks good to land ✅
What I verified:
-
Feature scope: Adds markdown transformer support for block/inline equation nodes in the playground. The
EQUATIONtransformer handles inline ($...$) andBLOCK_EQUATIONhandles block ($$...$$) math equations. -
Implementation quality: Clean TextMatchTransformer implementation. The regex patterns are correct — inline uses
/(?<!\$)\$(?!\$)(.+?)(?<!\$)\$(?!\$)/(excludes$$), block uses/^\$\$\n([\s\S]+?)\n\$\$/(multiline). Import/export logic properly handles theinlineflag on EquationNode. -
Test coverage: Comprehensive test suite (261 lines) covering export, import, round-trip, and markdown shortcut typing for both inline and block equations. Tests verify correct node creation, content preservation, and non-interference with other content.
-
CI status: Full CI suite green (39 checks pass).
-
Risk assessment: Playground-only change, adds new transformers without modifying existing ones. No regression risk.
— via Navi on behalf of potatowagon
Follow-ups to the block equation markdown support (facebook#8562): - Typing $$...$$ only converts to a block equation when it is the sole content of a top-level paragraph. Previously the parent element was replaced unconditionally, destroying soft-wrapped lines and formatted siblings and ejecting list items out of their list. - Inline equation export now escapes only bare `$` (as the KaTeX-valid `\$`) instead of doubling every backslash, and import keeps content verbatim instead of unescaping. Exported LaTeX like `$\frac{1}{2}$` renders correctly in external markdown renderers while bare `$` is still disambiguated from the delimiters. - An escaped dollar (`\$`) no longer opens an inline equation shortcut match, so markdown-style escapes are honored while typing. - Non-inline equations nested inside another element export in inline form again instead of silently dropping their delimiters. - Use $createEquationNode instead of the raw EquationNode constructor. Also adds a browser-mode suite that drives the shortcuts through real key events to cover caret behavior around the conversions, which the jsdom unit suite cannot observe. https://claude.ai/code/session_01WpKgF4fzRPkybpU6mwUXFB
Description
Preserves block equation markdown in the playground transformer by adding a block-level
$$...$$equation transformer and by teaching the existing equation text-match transformer to distinguish$$...$$from$...$during import.This keeps block equations from being serialized as inline equations when converting playground content to Markdown and back.
Closes #6936
Test plan
Before
A block
EquationNodeexported through the playground markdown transformers produced the raw equation text / inline-style markdown instead of preserving$$...$$delimiters.After
source ~/.nvm/nvm.sh && nvm use 20.20.0 >/dev/null && pnpm exec vitest --project unit packages/lexical-playground/__tests__/unit/MarkdownTransformers.test.ts --runsource ~/.nvm/nvm.sh && nvm use 20.20.0 >/dev/null && pnpm exec prettier --check packages/lexical-playground/src/plugins/MarkdownTransformers/index.ts packages/lexical-playground/__tests__/unit/MarkdownTransformers.test.tssource ~/.nvm/nvm.sh && nvm use 20.20.0 >/dev/null && pnpm exec eslint packages/lexical-playground/src/plugins/MarkdownTransformers/index.ts packages/lexical-playground/__tests__/unit/MarkdownTransformers.test.ts