Repository navigation
[lexical-markdown][lexical-mdast] Bug Fix: markdown round trip keeps fenced code and enclosing blocks intact - #9055
Merged
Conversation
…fenced code and enclosing blocks intact ## Description Markdown import and the markdown shortcuts lose or invent content on the round trip: the fenced-code transformer mishandles the fence's own text, a block shortcut replaces the block it is typed in instead of its contents, an escape sequence is read as a hard line break, and a text entity around the caret hides the heading shortcut. Seven fixes, one story — what comes back out is not what went in. - `CODE.handleImportAfterStartMatch` (`MarkdownTransformers.ts`) dropped a blank first line of a fenced code block. The remainder of the opening fence line was only unshifted onto `linesInBetween` when it was non-empty, so `replace` — which always discards `linesInBetween[0]` when blank — mistook a genuinely blank first content line for that remainder and threw it away. (meta#9003) - The same function imported a fence's info string as code: for an opening fence whose info string is `js title="x"` or `ts {1,3}`, everything after the language was prepended to the block's content. Only the first word of the info string is the language; the rest is metadata and is now dropped, while a fence with no language keeps its remainder as content as before. (meta#9020) - `CODE.replace` kept the fence's own indentation in the content of an indented code block. The new `stripFenceIndent` removes up to N leading spaces/tabs from each line, N being the indentation of the opening fence, per CommonMark. (meta#9004) - `parseMarkdownHardLineBreak` (`MarkdownTransformers.ts`) treated a trailing `\\` as a hard line break. That is an escaped backslash — a literal `\` followed by a soft line ending — so only an odd-length run of backslashes counts. (meta#9018) - `HEADING.replace` and `listReplace` (`MarkdownTransformers.ts`) replaced the enclosing `QuoteNode` when a block shortcut was typed at the start of a quote, so the quote was discarded out from under the caret. A quote holds inline content and has nowhere to nest the new block, so the shortcut now declines — which is what import already does for `> # x`. (meta#8956, meta#7407) - `@lexical/mdast` had the same defect in `$applyBlock` (`MdastShortcuts.ts`), with more room to fix it: an inline-content quote now adopts the new block as a child instead of being replaced by it, producing exactly the tree that importing `> ## H2` produces. A quote that already starts with a block is left alone. (meta#8957) - `registerMarkdownShortcuts` (`MarkdownShortcuts.ts`) skipped the shortcut when a node transform (hashtag, autolink, ...) split or merged the leaves around the caret during the same update: the raw anchor offsets before and after were no longer comparable, so a single typed character looked like a large jump. The new `$getOffsetInParent` rebases both offsets on the parent element. (meta#8978, meta#5366) ## Test plan New unit tests cover each defect — fenced-code import (leading blank line, fence indentation, info string), `parseMarkdownHardLineBreak`/`normalizeMarkdown` for the escaped backslash, the quote-preserving block shortcuts in both `@lexical/markdown` and `@lexical/mdast`, and the hashtag/heading shortcut repro for meta#5366 — plus one playground e2e case for meta#5366 that needs a built playground and therefore runs in CI's e2e job, not locally. ### Before Source fixes stashed, new tests kept: ```` $ npx vitest run --project unit packages/lexical-markdown packages/lexical-mdast × should preserve a quote when typing the "# " shortcut (meta#7407) 20ms × should preserve a quote when typing the "## " shortcut (meta#7407) 1ms × should preserve a quote when typing the "###### " shortcut (meta#7407) 1ms × should preserve a quote when typing the "1. " shortcut (meta#7407) 1ms × should preserve a quote when typing the "- " shortcut (meta#7407) 1ms × should preserve a quote when typing the "* " shortcut (meta#7407) 0ms × should preserve a quote when typing the "+ " shortcut (meta#7407) 0ms × ## -> heading nested in the quote 23ms × - -> bullet list nested in the quote 11ms × 1. -> ordered list nested in the quote 1ms × ```js + Enter -> code block nested in the quote 1ms × leaves the quote alone once it holds a block 1ms × transforms with the "## " shortcut typed before existing text 64ms × transforms with the "### " shortcut typed before existing text 1ms × transforms with the "#### " shortcut typed before existing text 8ms × transforms with the "##### " shortcut typed before existing text 53ms × transforms with the "###### " shortcut typed before existing text 1ms × keeps a blank first line of a fenced code block 9ms × keeps several blank first lines 1ms × round trips a code block that starts with a blank line 1ms × removes the fence indentation from the content 12ms × preserves indentation relative to the fence 2ms × removes at most the fence indentation 1ms × handles a tab-indented fence 1ms × does not treat an escaped backslash as a hard line break 3ms × merges a line ending in an escaped backslash with the next line 2ms × keeps the literal backslash in the imported text 11ms × does not put a title attribute into the code content 16ms × does not put a line-highlight range into the code content 3ms × does not put a bare info-string word into the code content 1ms Test Files 7 failed | 5 passed (12) Tests 30 failed | 604 passed (634) ```` ### After ``` $ npx vitest run --project unit packages/lexical-markdown packages/lexical-mdast Test Files 12 passed (12) Tests 634 passed (634) $ npx tsc --noEmit -p . (clean) ``` Supersedes meta#8956, meta#8957, meta#8978, meta#9003, meta#9004, meta#9018, meta#9020, consolidated per the review feedback on meta#9027 and meta#9035.
LeSingh1
requested review from
acywatson,
etrepum,
fantactuka,
ivailop7,
potatowagon and
zurfyx
as code owners
August 10, 2026 04:10
|
@LeSingh1 is attempting to deploy a commit to the Meta Open Source Team on Vercel. A member of the Team first needs to authorize it. |
This was referenced Aug 10, 2026
Closed
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
etrepum
reviewed
Aug 16, 2026
… the markdown round trip fixes ## Description Follow-up to meta#9055, addressing the three review comments on it. - `$getOffsetInParent` returned `point.offset` unchanged for a non-text point. That offset is a child index, not a character count, so the function mixed two coordinate spaces and the "did the user type exactly one character?" comparison could be made against a number that is not a text offset at all. It now starts at 0 for an element point — an element point sits on a child boundary, which is already a position in the parent's text coordinate space — and adds the preceding siblings' text content sizes in both cases. - `$isShortcutQuote` declared `node is QuoteNode`, so TypeScript treated a false result as proof that the node is not a QuoteNode. It is not: a QuoteNode that is nested, is a shadow root, or does not start at the anchor also returns false. The predicate now returns a branded `QuoteNode & {[ShortcutQuoteBrand]: never}`, matching the convention used by `INTERNAL_$isBlock` and `$isInlineElementOrDecoratorNode`, so the negative branch no longer subtracts `QuoteNode`. - The tests added with those fixes built their editor with `createHeadlessEditor` and a hand-listed `nodes` array. They now use `buildEditorFromExtensions`, with the shared node set factored out into `packages/lexical-markdown/src/__tests__/utils.ts` as `MarkdownTestExtension`. `Issue5366Repro` composes it with `HashtagExtension`, and `CodeBlockLeadingBlankLine` drops an `as unknown as string` cast that the extension rewrite made unnecessary. ## Test plan ### Before The unsound guard, reduced to a repro compiled with the repo's `tsc` (`$isShortcutQuoteOld` has the old `n is QuoteNode` signature, `$isShortcutQuoteNew` the branded one; both `return node` from the false branch): ``` $ npx tsc --noEmit -p tsconfig.json packages/lexical-mdast/src/guardRepro.ts(13,3): error TS2741: Property 'setIsShadowRoot' is missing in type 'HeadingNode' but required in type 'QuoteNode'. ``` The false branch of the unbranded guard narrows `QuoteNode | HeadingNode` to `HeadingNode`, even though a QuoteNode reaches it. The branded guard leaves the union intact and the same line compiles. ### After ``` $ npx tsc --noEmit -p tsconfig.json $ npx eslint packages/lexical-markdown packages/lexical-mdast $ npx prettier --check "packages/lexical-markdown/src/**/*.ts" "packages/lexical-mdast/src/**/*.ts" Checking formatting... All matched files use Prettier code style! $ npx vitest run packages/lexical-markdown packages/lexical-mdast Test Files 12 passed (12) Tests 718 passed (718) ``` Full `npx vitest run`: 301 test files passed, 5769 passed | 1 skipped. The 21 remaining files are the Vitest browser-mode project, which has no browser available in this environment; E2E (Playwright) was likewise not exercised here. Co-Authored-By: Claude <[email protected]>
…OffsetInParent ## Description Follow-up to the previous commit. `$getOffsetInParent` returned 0 for an element point regardless of its offset, so it was only correct when that offset was 0. An element point at offset N stands after N children, and the characters those children contribute are part of the point's text coordinate. It now sums them. Also documents why `MarkdownTestExtension` stays nodes-only. Registering `registerMarkdownShortcuts` there and passing `HashtagExtension` as a sibling in the `buildEditorFromExtensions` array does not reproduce meta#5366: depending on which sibling comes first, either no hashtag ever forms (the shortcut fires and the test passes with or without the fix) or the hashtag forms but the shortcut never fires (the test fails with or without the fix). Making HashtagExtension a dependency of the extension that registers the shortcuts reproduces the plain-editor behaviour exactly, so the registration stays with the test that needs the ordering. ## Test plan ### Before The regression test was vacuous with the shortcut registration in `MarkdownTestExtension` and `HashtagExtension` as a sibling. Probing the paragraph after each keystroke of `## ` typed before `Welcome to the playground`, with the meta#5366 fix reverted: ``` ext-md-first typed="#" block=paragraph kids=[text:"#Welcome to the playground"] ext-md-first typed="#" block=paragraph kids=[text:"##Welcome to the playground"] ext-md-first typed=" " block=heading kids=[text:"Welcome to the playground"] ``` No hashtag node ever forms, so the heading conversion succeeds with the fix reverted and the test cannot fail. Reversing the two siblings forms the hashtag but never converts, with or without the fix. ``` $ npx vitest run packages/lexical-markdown/src/__tests__/unit/Issue5366Repro.test.ts Tests 6 passed (6) # with the fix reverted ``` ### After With `HashtagExtension` as a dependency the probe matches a plain editor (`hashtag:"#Welcome"` after the first keystroke, heading after the third), and the test regresses as the equivalent `createHeadlessEditor` test did: ``` $ npx vitest run packages/lexical-markdown/src/__tests__/unit/Issue5366Repro.test.ts Tests 5 failed | 1 passed (6) # with the fix reverted Tests 6 passed (6) # with the fix applied $ npx vitest run packages/lexical-markdown packages/lexical-mdast Test Files 12 passed (12) Tests 718 passed (718) $ npx tsc --noEmit -p tsconfig.json $ npx eslint packages/lexical-markdown packages/lexical-mdast $ npx prettier --check "packages/lexical-markdown/src/**/*.ts" "packages/lexical-mdast/src/**/*.ts" All matched files use Prettier code style! ``` Playwright E2E and the Vitest browser-mode project were not exercised in this environment. Co-Authored-By: Claude <[email protected]>
…ing quote
## Description
Two gaps in the fenced-code and block-shortcut fixes.
The info string after a fence's language (```` ```js title="x" ````,
```` ```ts {1,3} ````) stopped being imported as code content, but was then
discarded: the block came back out as ```` ```js ````. `CodeNode` models only
the language, so the tail now goes into a new `codeMetaState`, mirroring
`codeFenceState` beside it, and `CODE.export` writes it back after the
language. A fence with no language, and an unterminated fence, keep their
long-standing behaviour of treating the remainder as content.
`$isUnreplaceableBlock` guarded `HEADING.replace` and `listReplace` but not
`CODE.replace`, so the fenced-code shortcut typed at the start of a quote
still replaced the quote with an empty code block and discarded its
contents — the same defect meta#7407 reports, through a different shortcut. The
shortcut path now declines in a quote like the others do.
## Test plan
### Before
```
$ npx vitest run packages/lexical-markdown/src/__tests__/unit/LexicalMarkdown.test.ts
× should preserve a quote when the code fence shortcut is typed in it (meta#7407)
Tests 1 failed | 507 passed (508)
```
and, probing a round trip of ```` ```js title="x"\ncode\n``` ````:
```
in="```js title=\"x\"\ncode\n```" out="```js\ncode\n```" same=false
```
### After
```
$ npx vitest run packages/lexical-markdown packages/lexical-mdast
Test Files 12 passed (12)
Tests 721 passed (721)
$ npx vitest run
Test Files 322 passed (322)
Tests 5914 passed | 2 skipped (5916)
$ npx tsc --noEmit -p tsconfig.json
$ npx eslint packages/lexical-markdown packages/lexical-mdast
$ npx prettier --check "packages/lexical-markdown/src/**/*.ts"
All matched files use Prettier code style!
```
Playwright E2E was not exercised in this environment.
Co-Authored-By: Claude <[email protected]>
… root
## Description
`$placeBlock` let an inline-content QuoteNode adopt the new block as a child
without opting the quote in to shadow root behaviour. A QuoteNode holds
block-level children only once `isShadowRoot()` is true — that is what
`quoteShadowRootState` and `setIsShadowRoot` are for — so the shortcut
produced a quote holding a heading with none of the state that makes the
shape legal. `$isShortcutQuote` matches only non-shadow-root quotes, so this
was every quote the shortcut nested into.
It now sets the flag as it adopts the block, which is the tree
`MdastShadowRootQuoteExtension` imports for `> ## H2`. The default
`$importBlockquote` produces the same unflagged shape for a nested block;
that is pre-existing and left alone here.
## Test plan
### Before
Typing `> `, `## `, `H2`, and dumping the tree:
```
shortcut : quote[shadow=false](heading(text"H2"))
MdastShadowRootQuoteExtension import of "> ## H2": quote[shadow=true](heading(text"H2"))
```
With the assertion added to the existing nesting test:
```
$ npx vitest run packages/lexical-mdast/src/__tests__/unit/MdastShortcuts.test.ts
× ## -> heading nested in the quote
Tests 1 failed | 26 passed (27)
```
### After
```
$ npx vitest run packages/lexical-mdast/src/__tests__/unit/MdastShortcuts.test.ts
Tests 27 passed (27)
$ npx vitest run
Test Files 322 passed (322)
Tests 5914 passed | 2 skipped (5916)
$ npx tsc --noEmit -p tsconfig.json
$ npx eslint packages/lexical-markdown packages/lexical-mdast
$ npx prettier --check "packages/lexical-mdast/src/**/*.ts"
All matched files use Prettier code style!
```
Playwright E2E was not exercised in this environment.
Co-Authored-By: Claude <[email protected]>
etrepum
approved these changes
Aug 30, 2026
etrepum
pushed a commit
to etrepum/lexical
that referenced
this pull request
Aug 30, 2026
…ing-nesting ## Description Syncs the branch with main, which has moved on considerably since the last merge. Conflict resolutions: - `HEADING`: main (meta#9055) made block-level shortcuts decline rather than replace an enclosing `QuoteNode`, via `$isUnreplaceableBlock`. The transformer built by `$createHeadingTransformer` keeps that guard for the default case and skips it when `nestInBlockquote` is on, where nesting is the point. - `index.ts`: keeps both this branch's `$createHeadingTransformer` / `$createQuoteTransformer` exports and main's `$generateNodesFromMarkdownString`. - The test asserting that typing `> # SOME HEADER` replaces the quote with a heading pinned the old default, which meta#9055 deliberately changed. It now asserts main's behavior: the quote survives and `# SOME HEADER` stays literal text. ## Test plan ### Before ``` $ npx vitest --project unit --no-watch packages/lexical-markdown packages/lexical-mdast × typing "> # SOME HEADER" replaces the quote with a heading by default AssertionError: Root child must be a HeadingNode (default behavior) Test Files 1 failed | 11 passed (12) Tests 1 failed | 727 passed (728) ``` ### After ``` $ npx vitest --project unit --no-watch packages/lexical-markdown packages/lexical-mdast Test Files 12 passed (12) Tests 728 passed (728) $ pnpm run lint && pnpm run flow No errors! ```
etrepum
pushed a commit
to etrepum/lexical
that referenced
this pull request
Aug 30, 2026
…ugh the shadow root QuoteNode
## Description
Addresses the review of this PR. The branch added `nestInBlockquote` to a
heading-transformer factory and `handleNestedHeadings` to a quote-transformer
factory, and put a `HeadingNode` inside an ordinary inline-content
`QuoteNode`. `QuoteNode` has since gained opt-in shadow root behavior
(`$createQuoteNode({shadowRoot: true})`) for exactly this — a quote that holds
block-level children — so this reworks the feature on top of it.
What changes:
- One factory instead of two. `createQuoteTransformer({shadowRoot: true})`
creates shadow root quotes; `HEADING` is untouched, because in a shadow root
quote the shortcut's `parentNode` is the inner paragraph, so the existing
transformer already replaces the right block. This removes the previous
hazard where the two options had different names, had to be enabled
together, and each did nothing useful alone: `nestInBlockquote` only
affected typing, `handleNestedHeadings` only import and export.
- No `$` prefix. These factories are called at module scope and touch no
editor state, which is the opposite of what `$` denotes, and
`@lexical/rules-of-lexical` warns on the call sites. `$createHeadingTransformer`
is gone; `$createQuoteTransformer` becomes `createQuoteTransformer`.
- Export walks the quote's block children rather than special-casing a quote
whose single child is a heading. Previously `> # HEADING\n> some text` came
back as `> HEADING\n> some text`, dropping the `#`, and pressing Enter in a
nested heading produced `> HeadingText` with no separator, because
`$exportChildren` joins element children with `''`. Both round trip now, as
does a heading containing a line break and a nested `> > quote`.
- Export is not gated on the option. A shadow root quote can come from
anywhere — pasting a `<blockquote>` through `RichTextImportExtension`, or
`@lexical/mdast` — so the default `QUOTE` exports its blocks too. That fixes
an existing bug where such a quote exported as `> firstsecond`.
- A quote continuation line during import goes to the last block of a shadow
root quote instead of to the quote itself, so it does not mix inline
children into a block container.
- Flow types for the new export, which were missing.
- `createQuoteTransformer` is declared `@__NO_SIDE_EFFECTS__` and added to
`PURE_FACTORY_FUNCTIONS`, so `export const QUOTE = createQuoteTransformer()`
is annotated by the build and stays tree-shakeable. Without that, turning a
plain object literal into a module-scope call pins it into every bundle.
- Tests use `using editor` like the rest of the file, so the editors are
disposed.
- README documents how to opt in.
meta#7407 is already closed by meta#9055, which stops the quote being dropped by
declining the shortcut. This is the other half: making the heading actually
nest, opt-in.
## Test plan
### Before
The export of a quote holding blocks ran them together, and a heading in a
multi-block quote lost its marker:
```
$ npx vitest run packages/lexical-markdown/src/__tests__/unit/ShadowRootQuoteExport.test.ts
× a shadow root quote exports one markdown line per block child
AssertionError: expected '> firstsecond' to be '> first\n> second'
Test Files 1 failed (1)
Tests 1 failed (1)
```
The branch's own test asserted the lossy behavior:
```js
expect(markdown).toBe('> HEADING\n> some text'); // '#' dropped
```
### After
```
$ npx vitest run packages/lexical-markdown/src/__tests__/unit/MarkdownTransformers.test.ts
✓ QUOTE with block children > typing "> # SOME HEADER" nests the heading inside the quote
✓ QUOTE with block children > typing "> " then "## " then text nests without the heading marker
✓ QUOTE with block children > typing "> # SOME HEADER" declines the heading by default
✓ QUOTE with block children > import "> # SOME HEADER" nests the heading inside the quote
✓ QUOTE with block children > a quote heading and its following text stay separate blocks
✓ QUOTE with block children > round trips "> # SOME HEADER"
✓ QUOTE with block children > round trips "> ### SOME HEADER"
✓ QUOTE with block children > round trips "> # HEADING\n> some text"
✓ QUOTE with block children > round trips "> some text\n> more text"
✓ QUOTE with block children > round trips "> # HEADING\n> # OTHER HEADING"
✓ QUOTE with block children > export keeps the heading marker of a quote with several blocks
✓ QUOTE with block children > export prefixes every line of a multi-line block child
✓ QUOTE with block children > export separates the blocks of a shadow root quote by default
✓ QUOTE with block children > export of an inline content quote is unchanged
✓ QUOTE with block children > pressing enter in a nested heading adds a paragraph to the quote
Test Files 1 passed (1)
Tests 28 passed (28)
```
```
$ pnpm run test-unit
Test Files 316 passed (316)
Tests 5696 passed | 1 skipped (5697)
$ pnpm run ci-check # tsc, flow, prettier, eslint
exit: 0
```
The build annotates the factory call, so `QUOTE` stays droppable:
```
export const QUOTE: ElementTransformer = /* @__PURE__ */createQuoteTransformer();
```
Browser-mode and E2E tests could not be exercised here: the pre-installed
Playwright browser does not match the version the runner expects, so
`pnpm run test-browser` cannot launch.
Co-Authored-By: Claude <[email protected]>
etrepum
pushed a commit
to etrepum/lexical
that referenced
this pull request
Aug 30, 2026
…ugh the shadow root QuoteNode
## Description
Addresses the review of this PR. The branch added `nestInBlockquote` to a
heading-transformer factory and `handleNestedHeadings` to a quote-transformer
factory, and put a `HeadingNode` inside an ordinary inline-content
`QuoteNode`. `QuoteNode` has since gained opt-in shadow root behavior
(`$createQuoteNode({shadowRoot: true})`) for exactly this — a quote that holds
block-level children — so this reworks the feature on top of it.
What changes:
- One factory instead of two. `createQuoteTransformer({shadowRoot: true})`
creates shadow root quotes; `HEADING` is untouched, because in a shadow root
quote the shortcut's `parentNode` is the inner paragraph, so the existing
transformer already replaces the right block. This removes the previous
hazard where the two options had different names, had to be enabled
together, and each did nothing useful alone: `nestInBlockquote` only
affected typing, `handleNestedHeadings` only import and export.
- No `$` prefix. These factories are called at module scope and touch no
editor state, which is the opposite of what `$` denotes, and
`@lexical/rules-of-lexical` warns on the call sites. `$createHeadingTransformer`
is gone; `$createQuoteTransformer` becomes `createQuoteTransformer`.
- Export walks the quote's block children rather than special-casing a quote
whose single child is a heading. Previously `> # HEADING\n> some text` came
back as `> HEADING\n> some text`, dropping the `#`, and pressing Enter in a
nested heading produced `> HeadingText` with no separator, because
`$exportChildren` joins element children with `''`. Both round trip now, as
does a heading containing a line break and a nested `> > quote`.
- Export is not gated on the option. Shadow root quotes are also produced by
`ShadowRootQuoteRule` and by `MdastShadowRootQuoteExtension` (both opt-in
and experimental), so the default `QUOTE` exports their block children too
rather than running them together. That fixes an existing bug where such a
quote exported as `> firstsecond`.
- A quote continuation line during import goes to the last block of a shadow
root quote instead of to the quote itself, so it does not mix inline
children into a block container.
- Flow types for the new export, which were missing.
- `createQuoteTransformer` is declared `@__NO_SIDE_EFFECTS__` and added to
`PURE_FACTORY_FUNCTIONS`, so `export const QUOTE = createQuoteTransformer()`
is annotated by the build and stays tree-shakeable. Without that, turning a
plain object literal into a module-scope call pins it into every bundle.
- Tests use `using editor` like the rest of the file, so the editors are
disposed.
- README documents how to opt in.
meta#7407 is already closed by meta#9055, which stops the quote being dropped by
declining the shortcut. This is the other half: making the heading actually
nest, opt-in.
## Test plan
### Before
The export of a quote holding blocks ran them together, and a heading in a
multi-block quote lost its marker:
```
$ npx vitest run packages/lexical-markdown/src/__tests__/unit/ShadowRootQuoteExport.test.ts
× a shadow root quote exports one markdown line per block child
AssertionError: expected '> firstsecond' to be '> first\n> second'
Test Files 1 failed (1)
Tests 1 failed (1)
```
The branch's own test asserted the lossy behavior:
```js
expect(markdown).toBe('> HEADING\n> some text'); // '#' dropped
```
### After
```
$ npx vitest run packages/lexical-markdown/src/__tests__/unit/MarkdownTransformers.test.ts
✓ QUOTE with block children > typing "> # SOME HEADER" nests the heading inside the quote
✓ QUOTE with block children > typing "> " then "## " then text nests without the heading marker
✓ QUOTE with block children > typing "> # SOME HEADER" declines the heading by default
✓ QUOTE with block children > import "> # SOME HEADER" nests the heading inside the quote
✓ QUOTE with block children > a quote heading and its following text stay separate blocks
✓ QUOTE with block children > round trips "> # SOME HEADER"
✓ QUOTE with block children > round trips "> ### SOME HEADER"
✓ QUOTE with block children > round trips "> # HEADING\n> some text"
✓ QUOTE with block children > round trips "> some text\n> more text"
✓ QUOTE with block children > round trips "> # HEADING\n> # OTHER HEADING"
✓ QUOTE with block children > export keeps the heading marker of a quote with several blocks
✓ QUOTE with block children > export prefixes every line of a multi-line block child
✓ QUOTE with block children > export separates the blocks of a shadow root quote by default
✓ QUOTE with block children > export of an inline content quote is unchanged
✓ QUOTE with block children > pressing enter in a nested heading adds a paragraph to the quote
Test Files 1 passed (1)
Tests 28 passed (28)
```
```
$ pnpm run test-unit
Test Files 316 passed (316)
Tests 5696 passed | 1 skipped (5697)
$ pnpm run ci-check # tsc, flow, prettier, eslint
exit: 0
```
The build annotates the factory call, so `QUOTE` stays droppable:
```
export const QUOTE: ElementTransformer = /* @__PURE__ */createQuoteTransformer();
```
Browser-mode and E2E tests could not be exercised here: the pre-installed
Playwright browser does not match the version the runner expects, so
`pnpm run test-browser` cannot launch.
Co-Authored-By: Claude <[email protected]>
etrepum
pushed a commit
to etrepum/lexical
that referenced
this pull request
Aug 30, 2026
…t quote
## Description
`QuoteNode` supports opt-in shadow root behavior
(`$createQuoteNode({shadowRoot: true})`), where the quote holds block-level
children instead of inline content. `ShadowRootQuoteRule` and
`MdastShadowRootQuoteExtension` both produce such quotes, but
`@lexical/markdown` did not know about them: `QUOTE.export` called
`exportChildren` on the quote, and `$exportChildren` joins element children
with `''`. A quote holding two paragraphs exported as `> firstsecond`, and a
heading child lost its `#` marker entirely — silent data loss for anyone who
opts into either rule and then exports markdown.
Quote export now walks the block children of a shadow root quote, exporting
each on its own line with its own markdown syntax (a heading child keeps its
`#`, a nested shadow root quote keeps its own `> `), and prefixes every
resulting line with `> `. An inline-content quote takes the same path it
always has.
This closes no issue. It is not the nesting feature this branch previously
carried: `> # Heading` still declines the shortcut (meta#9055) and
`@lexical/markdown` still creates inline-content quotes, so nothing changes
for a caller using the default transformers. `@lexical/mdast` remains the
package that parses block-level markdown inside a blockquote.
## Test plan
### Before
```
$ npx vitest --project unit --no-watch packages/lexical-markdown/src/__tests__/unit/ShadowRootQuoteExport.test.ts
× each block child is exported on its own quoted line
× a heading child keeps its markdown syntax
× every line of a multi-line block child is prefixed
× a nested shadow root quote keeps its own prefix
× a blockquote imported with ShadowRootQuoteRule round trips
AssertionError: expected '> firstsecond' to be '> first\n> second'
AssertionError: expected '> HEADINGsome text' to be '> ## HEADING\n> some text'
AssertionError: expected '> first\n> second' to be '> # first\n> second'
AssertionError: expected '> inner' to be '> > inner'
AssertionError: expected '> firstsecond' to be '> first\n> second'
Tests 5 failed | 1 passed (6)
```
### After
```
$ npx vitest --project unit --no-watch packages/lexical-markdown/src/__tests__/unit/ShadowRootQuoteExport.test.ts
✓ shadow root quote export > each block child is exported on its own quoted line
✓ shadow root quote export > a heading child keeps its markdown syntax
✓ shadow root quote export > every line of a multi-line block child is prefixed
✓ shadow root quote export > a nested shadow root quote keeps its own prefix
✓ shadow root quote export > an inline content quote is unchanged
✓ shadow root quote export > a blockquote imported with ShadowRootQuoteRule round trips
Tests 6 passed (6)
$ pnpm run test-unit
Test Files 317 passed (317)
Tests 5687 passed | 1 skipped (5688)
$ pnpm run ci-check # tsc, flow, prettier, eslint
ci-check exit: 0
```
Browser-mode and E2E tests could not be exercised in this environment: the
pre-installed Playwright browser does not match the version the runner
expects, so `pnpm run test-browser` cannot launch.
Co-Authored-By: Claude <[email protected]>
etrepum
pushed a commit
to etrepum/lexical
that referenced
this pull request
Aug 31, 2026
…r shadow root quotes in Markdown ## Description The blockquote nesting this branch adds was reachable only by an application assembling its own transformer array, so it could not be tried in the playground and had no e2e coverage. Typing `> ` then `# Heading` in the playground declines the heading (meta#9055) whatever this branch does, because `PLAYGROUND_TRANSFORMERS` spreads the default `ELEMENT_TRANSFORMERS`. This restores `createQuoteTransformer` (removed in the previous commit) and puts it behind a playground setting, "Shadow root quotes in Markdown", so the behavior can be toggled at runtime and exercised by e2e tests with the setting flipped both ways. - `shadowRootQuotes` joins `DEFAULT_SETTINGS`, off by default, with a `Switch` in the settings panel. - `playgroundTransformers(shadowRootQuotes)` selects between `PLAYGROUND_TRANSFORMERS` and a copy with the quote transformer swapped. - `PlaygroundMarkdownShortcutsExtension` gains a `shadowRootQuotes` config signal and re-registers the shortcuts through an `effect`, so the toggle applies to the live editor rather than rebuilding it — the same shape as the other settings driven by `synchronizeSettingsToSignals`. - The Markdown toggle in `ActionsPlugin` uses the same selector, so import and export round-trip consistently with the setting. The export fix from the previous commit is unchanged and remains ungated: a shadow root quote is exported as its block children whoever created it. ## Test plan ### Before The setting did not exist, and the playground had no way to reach the behavior. Typing `> ` then `# x` in the playground produced, on this branch: ``` <blockquote class="PlaygroundEditorTheme__quote" dir="auto"> <span data-lexical-text="true"># x</span> </blockquote> ``` ### After New e2e spec, run against the dev server with the pre-installed Chromium: ``` $ E2E_BROWSER=chromium npx playwright test --project=chromium \ packages/lexical-playground/__tests__/e2e/ShadowRootQuotes.spec.mjs ✓ setting off › the heading shortcut is declined inside a quote ✓ setting on › the heading shortcut nests the heading inside the quote ✓ setting on › the quote round trips through the markdown toggle ✓ setting on › text typed after the nested heading stays inside the quote 4 passed (8.5s) ``` Collab mode (the round-trip case skips there, as the markdown toggle is not exercised under collab): ``` $ E2E_EDITOR_MODE=rich-text-with-collab E2E_BROWSER=chromium npx playwright test \ --project=chromium packages/lexical-playground/__tests__/e2e/ShadowRootQuotes.spec.mjs 1 skipped 3 passed (13.7s) ``` ``` $ pnpm run test-unit Test Files 317 passed (317) Tests 5698 passed | 1 skipped (5699) $ pnpm run ci-check # tsc, flow, prettier, eslint ci-check exit: 0 ``` Firefox and WebKit were not exercised: only Chromium is available in this environment. Co-Authored-By: Claude <[email protected]>
Merged
This was referenced Oct 20, 2026
This branch was successfully deployed
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.
Description
Markdown import and the markdown shortcuts lose or invent content on the round
trip: the fenced-code transformer mishandles the fence's own text, a block
shortcut replaces the block it is typed in instead of its contents, an escape
sequence is read as a hard line break, and a text entity around the caret hides
the heading shortcut. Ten fixes, one story — what comes back out is not what
went in.
Closes #5366, closes #7407
CODE.handleImportAfterStartMatch(MarkdownTransformers.ts) dropped a blankfirst line of a fenced code block. The remainder of the opening fence line was
only unshifted onto
linesInBetweenwhen it was non-empty, soreplace— whichalways discards
linesInBetween[0]when blank — mistook a genuinely blank firstcontent line for that remainder and threw it away. ([lexical-markdown] Bug Fix: keep a blank first line of a fenced code block #9003)
fence whose info string is
js title="x"orts {1,3}, everything after thelanguage was prepended to the block's content. Only the first word of the info
string is the language; the rest is metadata and is no longer treated as
content. A fence with no language keeps its remainder as content as before, as
does an unterminated fence. ([lexical-markdown] Bug Fix: don't import a code fence's info string as code #9020)
CodeNodemodels only the language: animported
```js title="x"came back out as```js. Theinfo-string tail now goes into a new
codeMetaState— mirroringcodeFenceStatebeside it — and
CODE.exportwrites it back after the language, so the infostring survives the round trip.
CODE.replacekept the fence's own indentation in the content of an indentedcode block. The new
stripFenceIndentremoves up to N leading spaces/tabs fromeach line, N being the indentation of the opening fence, per CommonMark. The
indentation is not restored on export, since it is not part of the content. ([lexical-markdown] Bug Fix: strip the fence indentation from an indented code block #9004)
parseMarkdownHardLineBreak(MarkdownTransformers.ts) treated a trailing\\as a hard line break. That is an escaped backslash — a literal
\followed by asoft line ending — so only an odd-length run of backslashes counts. This is
observable when importing with
shouldMergeAdjacentLines; with the defaultsettings the merge branch that consumes the result is already satisfied. ([lexical-markdown] Bug Fix: an escaped backslash is not a hard line break #9018)
HEADING.replaceandlistReplace(MarkdownTransformers.ts) replaced theenclosing
QuoteNodewhen a block shortcut was typed at the start of a quote, sothe quote was discarded out from under the caret. A quote holds inline content
and has nowhere to nest the new block, so the shortcut now declines — which is
what import already does for
> # x. Note this preserves the quote rather thannesting the heading inside it;
@lexical/mdastbelow does nest, which is whatBug: Markdown block quotes containing headers dropping quote #7407 asks for. ([lexical-markdown] Bug Fix: block shortcuts no longer discard the enclosing block quote #8956, Bug: Markdown block quotes containing headers dropping quote #7407)
CODE.replacehad the same defect on its shortcut path and was not covered bythat guard, so a fenced-code shortcut typed at the start of a quote still
replaced the quote with an empty code block and discarded its contents. It now
declines in a quote like the heading and list shortcuts do.
@lexical/mdasthad the block-shortcut defect in$applyBlock(
MdastShortcuts.ts), with more room to fix it: an inline-content quote nowadopts the new block as a child instead of being replaced by it. A quote that
already starts with a block is left alone. ([lexical-mdast] Bug Fix: block shortcuts typed inside a blockquote #8957)
$placeBlocklet that quote adopt the block without opting it in to shadow rootbehaviour. A
QuoteNodeholds block-level children only onceisShadowRoot()istrue — that is what
quoteShadowRootStateandsetIsShadowRootare for — and$isShortcutQuotematches only non-shadow-root quotes, so this was every quotethe shortcut nested into. It now sets the flag as it adopts the block, producing
the tree
MdastShadowRootQuoteExtensionimports for> ## H2. The default$importBlockquoteproduces the same unflagged shape for a nested block; that ispre-existing and left alone here.
registerMarkdownShortcuts(MarkdownShortcuts.ts) skipped the shortcut when anode transform (hashtag, autolink, ...) split or merged the leaves around the
caret during the same update: the raw anchor offsets before and after were no
longer comparable, so a single typed character looked like a large jump. The new
$getOffsetInParentrebases both offsets on the parent element, counting a textpoint's own offset and an element point's preceding children. ([lexical-markdown] Bug Fix: hashtag no longer blocks the heading shortcut #8978, Bug: Hashtag blocks transformation to Headings #5366)
Test plan
New unit tests cover each defect — fenced-code import and round trip (leading
blank line, fence indentation, info string and its metadata),
parseMarkdownHardLineBreak/normalizeMarkdownfor the escaped backslash, thequote-preserving heading, list and code-fence shortcuts in
@lexical/markdown,the nesting shortcuts in
@lexical/mdastincluding the adopting quote's shadowroot state, and the hashtag/heading shortcut repro for #5366 — plus one playground
e2e case for #5366 that needs a built playground and therefore runs in CI's e2e
job, not locally.
Supersedes #8956, #8957, #8978, #9003, #9004, #9018, #9020, consolidated per the
review feedback on #9027 and #9035.