Repository navigation
[lexical-mdast] Feature: Unify MdastExtension and inherit export rules - #9198
Merged
etrepum merged 7 commits intoSep 23, 2026
Merged
Conversation
…herit export rules
## Description
The core mdast registry is named `MdastImportExtension` even though it configures both import and export. Export rules currently match only exact type strings, so a text rule does not handle tabs or custom text subclasses.
- Make `MdastExtension` the configurable core extension with both import and export APIs. Preserve `MdastImportExtension` as a `@deprecated` alias, its existing output type, and the `MdastExportExtension` compatibility API.
- Allow export rule types to be strings or node classes. Resolve each registered node's nearest matching ancestor at editor build time, preserving contribution order for rules targeting the same type. Ancestors need not be registered; abstract node classes are supported too.
- Let tabs inherit the text rule, and keep inherited custom handlers active during text-run accumulation and selection export.
- Update TypeScript/Flow declarations, documentation, and demo configuration.
The existing `MdastExtension` import/export bundle and the old configurable registry are consolidated. Consequently, import-only editors now also include the serializer; the documentation and size-probe comments call out this packaging change.
## Test plan
### Before
Run the new regression tests on `83e8b4925`:
```sh
node node_modules/vitest/vitest.mjs --project unit --run \
packages/lexical-mdast/src/__tests__/unit/MdastExportRules.test.ts \
packages/lexical-mdast/src/__tests__/unit/MdastExtension.test.ts
```
```text
Test Files 2 failed (2)
Tests 10 failed | 7 passed (17)
```
### After
```sh
pnpm run test-unit packages/lexical-mdast dev-examples/mdast-editor
```
```text
Test Files 7 passed (7)
Tests 223 passed (223)
```
Also passed:
- Source tree-shaking tests (335 tests).
- `pnpm exec tsc --noEmit` and the mdast demo's TypeScript check.
- `pnpm run build-types`.
- `pnpm run flow` (`Found 0 errors`).
- ESLint and Prettier on the changed code/files; `git diff --check`.
Tests ran on Linux with Node 24 and jsdom. The real-browser/OS matrix was not exercised.
…in mdast rules ## Description Use node class references for built-in and demo export rules without adding package dependencies. Normalize rule keys to strings and reject classes with no own node type using an invariant during editor construction. Document the current API without migration history or obsolete bundle-size measurements. ## Test plan ### Before On aa5bbba with the new rejection tests: ```sh node node_modules/vitest/vitest.mjs --project unit --run packages/lexical-mdast/src/__tests__/unit/MdastExportRules.test.ts ``` ```text Test Files 1 failed (1) Tests 3 failed | 9 passed (12) ``` ### After ```sh pnpm run test-unit packages/lexical-mdast dev-examples/mdast-editor scripts/__tests__/unit/treeShakingSource.test.ts ``` ```text Test Files 8 passed (8) Tests 560 passed (560) ``` TypeScript checks for the monorepo and mdast demo, ESLint, Prettier, and git diff --check also pass. Tests ran on Linux with Node 24 and jsdom; the real-browser/OS matrix was not exercised.
## Description Both deprecated extension names now alias MdastExtension, and both deprecated output types alias the fully documented MdastExtensionOutput interface. Update the demo to use the canonical extension and remove the unused source shim. Reject export-rule classes that inherit their type without declaring one, including after node metadata has been cached. Keep legacy static getType classes supported. Add formatted-tab regressions for the built-in text rule and the demo's HTML text rule, and preserve the accumulated Markdown format when importing a TabNode. Remove the redundant import-only size probe and restore the README's legacy-versus-mdast size comparison without its import-only row. Correct the probe's production-artifact filename check. ## Test plan ### Before Run the updated regression tests on c0b85fd: ```sh node node_modules/vitest/vitest.mjs --project unit --run \ packages/lexical-mdast/src/__tests__/unit/MdastExtension.test.ts \ packages/lexical-mdast/src/__tests__/unit/MdastExportRules.test.ts \ packages/lexical-mdast/src/__tests__/unit/MdastImportExport.test.ts \ dev-examples/mdast-editor/src/__tests__/unit/MdastCustomConstructs.test.ts ``` ```text Test Files 4 failed (4) Tests 6 failed | 154 passed (160) ``` ### After ```sh pnpm run test-unit packages/lexical-mdast dev-examples/mdast-editor scripts/__tests__/unit/treeShakingSource.test.ts ``` ```text Test Files 8 passed (8) Tests 565 passed (565) ``` Also passed: - pnpm exec tsc --noEmit - pnpm --dir dev-examples/mdast-editor exec tsc --noEmit - pnpm run build-types - pnpm run flow (Found 0 errors) - ESLint and Prettier on changed files - node --check dev-examples/mdast-editor/size/measure.mjs - git diff --check Tests ran on Linux with Node 24 and jsdom. The real-browser/OS matrix was not exercised. The README restores the existing size snapshot; it was not remeasured.
## Description
The handler type documentation promises a chain of registered handlers, but
compilation selects one handler per type. Document the existing behavior:
a null export result uses the default export, while a null import result
omits the node and its children. Clarify this in the package README too.
Add regressions for null export results with both string and class rules,
including lower-priority rules and a custom parent TextNode rule, and for
null import results. Comment that export rules resolve against registered
node classes, including replacements.
## Test plan
### Before
This is a documentation correction; the new behavior tests already pass on
the existing implementation. The inaccurate documentation was:
```sh
rg -n 'defers to the next registered handler' packages/lexical-mdast/src/types.ts
```
```text
106: * nodes. Returning `null` defers to the next registered handler.
155: * defers to the next registered handler.
```
### After
```sh
pnpm run test-unit packages/lexical-mdast/src/__tests__/unit/MdastExportRules.test.ts packages/lexical-mdast/src/__tests__/unit/MdastImportExport.test.ts
```
```text
Test Files 2 passed (2)
Tests 113 passed (113)
```
Also passed: pnpm exec tsc --noEmit, ESLint and Prettier on changed TypeScript
files, and git diff --check. Tests ran on Linux with Node 24 and jsdom; the
real-browser/OS matrix was not exercised.
## Description Import and export handlers currently cannot delegate to lower-priority rules. Compile ordered handler chains and expose context.next(), which converts the same node through the remaining handlers and returns a normalized output array. Export chains put same-type rules before ancestor rules, nearest first; import chains retain contribution order. Each continuation captures its node, chain, and position so nested conversion cannot disturb it. Preserve null semantics: default export on export, omission on import. An empty array omits content in either direction. Exhausting a chain invokes the generic fallback. Keep the ordinary text accumulation fast path, and group eligible formatted output after custom text middleware runs so pass-through middleware preserves tabs and overlapping formats. Preserve custom structure and metadata. Update TypeScript, Flow, package documentation, and website documentation. ## Test plan ### Before Run the middleware regressions against 666d57d: ```sh node node_modules/vitest/vitest.mjs --project unit --run packages/lexical-mdast/src/__tests__/unit/MdastMiddleware.test.ts ``` ```text Test Files 1 failed (1) Tests 15 failed | 1 passed (16) ``` ### After ```sh pnpm run test-unit packages/lexical-mdast dev-examples/mdast-editor scripts/__tests__/unit/treeShakingSource.test.ts ``` ```text Test Files 9 passed (9) Tests 584 passed (584) ``` Coverage includes mixed string/class priority, unregistered ancestors, node replacements, nested import/export, selection slicing, generic fallbacks, null/empty output, formatted tabs in inline/block walks, overlapping formats, and preservation of custom output and metadata. Also passed: - pnpm exec tsc --noEmit - pnpm --dir dev-examples/mdast-editor exec tsc --noEmit - pnpm run build-types - pnpm run flow (Found 0 errors) - ESLint and Prettier on changed TypeScript files - git diff --check Tests ran on Linux with Node 24 and jsdom; the real-browser/OS matrix was not exercised.
… output ## Description The uppercase middleware example only visits top-level text output, so bold, italic, and inline-code output remain unchanged. Walk the returned mdast tree to uppercase text inside formatting containers and inline code. Explain that extra fields such as data and custom structures prevent merging text output, preserving those fields while making middleware responsible for valid standalone serialization. Compare next(), null, and empty-array results for import and export in one table. ## Test plan ### Before Extract the original README snippet and invoke its export handler with next() returning representative mdast output (capture the handler with import stubs): ```sh node /tmp/mdast-readme-probe.cjs /tmp/mdast-readme-before.ts ``` ```text plain: PLAIN (PASS) bold: bold (FAIL) italic: italic (FAIL) nested: nested (FAIL) code: code (FAIL) ``` ### After ```sh node /tmp/mdast-readme-probe.cjs packages/lexical-mdast/README.md ``` ```text plain: PLAIN (PASS) bold: BOLD (PASS) italic: ITALIC (PASS) nested: NESTED (PASS) code: CODE (PASS) ``` The extracted example also passes TypeScript checking against the repository's source declarations. git diff --check passes. This change only edits the README; the runtime test suite and real-browser/OS matrix were not rerun.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
etrepum
marked this pull request as ready for review
September 23, 2026 03:45
etrepum
requested review from
acywatson,
fantactuka,
ivailop7,
potatowagon and
zurfyx
as code owners
September 23, 2026 03:45
potatowagon
approved these changes
Sep 23, 2026
Merged
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.
Breaking Changes
MdastImportExtensionandMdastExportExtensionand their associated config and output types are now deprecated, you should move all configurations to the unifiedMdastExtension. Since this is a new@experimentalpackage, this deprecation will only last for one release.Description
Simplify the
@lexical/mdastinterface by consolidating import and export into a singleMdastExtensioninstead of separateMdastImportExtensionandMdastExportExtension. The original separation was confusing (export rules were configured on the import extension) and really only saved about 4kB for a niche import-only use case.Other improvements:
typeto also accept a concrete LexicalNode class (or the node type string)context.next(): delegate conversion of the same node to remaining handlers and receive an output array to return or modify. Export chains try same-type rules before ancestor rules; import chains follow contribution order. Nested conversion has independent continuations, and exhausting a chain reaches the generic fallback.nullretains its existing default-export/omit-import meaning;[]omits content in both directions.Test plan
Additional unit tests to cover new behavior