Repository navigation
Conversation
…custom node guide ## Description The "Custom Nodes" steps in AGENTS.md predate `$config` serialization schemas. They only say to implement `$config()`, `createDOM()` and `updateDOM()`, so agents still hand-write `afterCloneFrom`, `exportJSON` and `importDOM`. This rewrites the steps to say: - Declare every inherent property in a `nodeSchema` passed as `$config`'s `json`, using `withField` for properties stored in a field, and initialize those fields. - Do not hand-write `clone`, `importJSON`, `exportJSON`, `updateFromJSON` or `afterCloneFrom` for schema properties, because `$config` derives them. A field left out of the schema is lost on the next clone. - Use NodeState for ad-hoc data. - Import HTML through `DOMImportExtension` rules, not a new `importDOM()`. It also links the schema and cloning docs. ## Test plan ### Before Documentation only. `AGENTS.md` told agents to implement only `$config()`, `createDOM()` and `updateDOM()`. ### After ``` $ prettier --check AGENTS.md Checking formatting... All matched files use Prettier code style! ``` Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…discouraging importDOM ## Description The custom node steps told agents not to add `importDOM()` to new nodes. `importDOM` is not deprecated, so the step now only recommends an import rule contributed through `DOMImportExtension`. ## Test plan ### Before Documentation only. Step 5 said "Do not add `importDOM()` to new nodes." ### After ``` $ prettier --check AGENTS.md All matched files use Prettier code style! ``` Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…GENTS.md ## Description The custom node steps prefer `DOMImportExtension` rules for HTML import. They now also say that `importDOM()` is not deprecated yet, but its deprecation is planned. ## Test plan ### Before Documentation only. Step 5 did not mention the status of `importDOM()`. ### After ``` $ prettier --check AGENTS.md All matched files use Prettier code style! ``` Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
etrepum
pushed a commit
that referenced
this pull request
Oct 31, 2026
…ling the link ## Description Export wrote no character reference inside a bare URL or `www.` host, or for the letter right before a scheme, so formatting that needed one there was lost. It also wrote markers and code spans right after a URL, which GFM readers (micromark for `@lexical/mdast`, and cmark-gfm) take into the link, so the formatting came back as literal markers inside a link: `**www.x.co**a` and `see https://x.com/a**“x”**`. Export now writes the reference, and where a URL that GFM readers would link would hold one, or would take in the markers, code span or other raw output after it, it also writes the `.` of `www.` or the `:` after the scheme as a reference (`**www.x.co**a`, `see https://x.com/&meta#97;**“x”**`). No reader then links it, and the text and formats come through in `@lexical/markdown`, `@lexical/mdast` and cmark-gfm. A reference that already lands in the prefix spoils the link by itself, and a URL that a reference before it would start is spoiled the same way. Emails and `mailto:` addresses need nothing: both readers find them in the decoded text and take in no format. A URL is found as GFM readers start one: `www.` only at the start of a run or after `*_~(`, a scheme after anything but a letter. Raw output keeps its letters and `*_~(` for that scan, so a URL runs on into it as it does for the readers. This also fixes plain text such as `[hello]](https://lexical.dev)` before a link, whose URL GFM readers ran on into the link. ## Test plan Command: `pnpm exec vitest run --project unit packages/lexical-markdown/src/__tests__/unit/LexicalMarkdown.test.ts` ### Before With this commit's tests and the previous `MarkdownExport.ts`: ``` × can export "[hello]](https://lexical.dev)[world](https://lexical.dev)" 17ms × exports formatting beside a `www.` host, which both importers read back 2ms × exports formatting beside an email, whose references readers decode first, which both importers read back 1ms × exports formatting beside a URL, which both importers read back 1ms × exports formatting beside an `xmpp:` address, whose references readers decode first, which both importers read back 1ms × exports formatting beside a `www.` host after `_`, which both importers read back 1ms × exports formatting beside a URL with a Unicode host, which both importers read back 1ms × exports formatting beside a URL that holds an emoji, which both importers read back 1ms × exports formatting beside the start of a `www.` host, which its reference spoils, which both importers read back 1ms × exports formatting beside the start of a URL, which its reference spoils, which both importers read back 1ms × exports formatting beside the start of `mailto:`, which its reference spoils, which both importers read back 1ms × exports formatting beside the start of an email, which both importers read back 1ms × exports formatting beside a URL that a reference before it would start, which both importers read back 1ms × exports formatting beside `mailto:`, which a reference before it does not change, which both importers read back 1ms × exports formatting beside a URL right after a code span, which both importers read back 1ms × exports formatting beside an email before a URL, which both importers read back 1ms × exports formatting beside a URL that would take in a code span, which both importers read back 1ms × exports formatting beside a URL that runs on through formats, which both importers read back 1ms × exports formatting beside a `www.` host that would take in markers, which both importers read back 1ms × exports formatting beside a `www.` host that would take in italic, which both importers read back 1ms × exports formatting beside a `www.` host that would take in markers after `:`, which both importers read back 1ms × exports formatting beside a `www.` host that would take in a code span, which both importers read back 1ms × exports formatting beside a URL that would take in strikethrough, which both importers read back 1ms × exports formatting beside a URL that holds a `www.` host, which both importers read back 1ms × exports formatting beside a URL that would take in the backslash of an escape at its end, which both importers read back 1ms × exports formatting beside a URL that holds an email, which both importers read back 1ms × spoils a URL for the reference to a backslash before a marker 1ms × spoils a URL for the reference to a tag character before its marker 1ms ⎯⎯⎯⎯⎯⎯ Failed Tests 28 ⎯⎯⎯⎯⎯⎯⎯ Test Files 1 failed (1) Tests 28 failed | 747 passed (775) ``` ### After ``` Test Files 1 passed (1) Tests 775 passed (775) ``` The new expectations were also checked by hand against cmark-gfm. On 80,000 random paragraphs of URL fragments and formats, against the previous commit, no export reads back worse in `@lexical/markdown`, `@lexical/mdast` or cmark-gfm, and about 1,700 in 20,000 more read back right in each GFM reader. Co-Authored-By: Claude Opus 5.5 <[email protected]>
etrepum
pushed a commit
that referenced
this pull request
Oct 31, 2026
## Description Merges main at cfcd3c4, which brings meta#9600 (escape a literal bracket only where it would start a link). It conflicted with this branch in four files: - `MarkdownExport.ts`: text escaping keeps this branch's `shouldPreserveNewLines` backslash handling and `toCharacterReference`, and routes default-mode text through meta#9600's `$escapeLiteralBrackets` instead of writing every bracket as a reference. meta#9600's bracket helpers sit beside this branch's piece joining. - `importTextMatchTransformer.ts`: `matchLink` combines meta#9600's code-span rules (no link opens inside a code span, or has its `](` or `)` in one) with this branch's bounded search (stop at the last `](`, jump over escaped openers, start at the real opener). A search rejected for a code span now jumps to the code span's end or the label's last character, since every `[` before it finds the same rejected link. The code spans come from the line's format scan when the code transformer is present. A link with an empty label after its real opener, as in `x[[](u)`, now stays text as meta#9600 has it, like `[](u)` does, rather than becoming an empty link that dropped `](u)`. - `LexicalMarkdown.test.ts`: `[hello]](https://lexical.dev)[world](...)` exports as `[hello]&meta#93;(https://lexical.dev)[world](https://lexical.dev)`: meta#9600's bracket escape, plus this branch's spoiled scheme so that GFM readers do not run the URL on into the next link. - `MarkdownEscaping.test.ts`: both sides made the same change to the unbalanced-link test; main's version is kept. ## Test plan Command: `pnpm exec vitest run --project unit packages/lexical-markdown packages/lexical-mdast packages/lexical-playground/__tests__/unit scripts/__tests__/unit/treeShakingSource.test.ts` ### After ``` Test Files 46 passed (46) Tests 1599 passed (1599) ``` `matchLink` was compared with main's on 150,000 random lines of brackets, parentheses, escapes and backticks, using the same code spans: no differences. Export and import round trips of 20,000 random paragraphs with links, brackets, formats and bare URLs found none that main reads back correctly and this branch does not, in either `@lexical/markdown` or `@lexical/mdast`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
etrepum
pushed a commit
that referenced
this pull request
Oct 31, 2026
…de the edge of a line again, and keep a referenced character inside a bare URL ## Description On main, the text after a text match is imported on its own, so a delimiter run at its start reads as one at the start of a line. This branch gave that text the match's last character as its neighbour, and the text before a match the match's first character, so that a delimiter run that a match cuts reads as it did in the whole line. For a custom transformer whose syntax ends or starts in a letter, that broke round trips: mention `user:bob` then bold `(admin)` exports as `user:bob**(admin)**`, as before, but re-imported as literal `**(admin)**`, and the exporter cannot put a reference inside transformer output to avoid it. The text beside a text match now reads the match's edge as the edge of a line again, as on main, unless a delimiter run goes on across the cut. The line's scan is still reused for the text after the match. Such a run can then only differ in whether it opens, since nothing in that text comes before it, and so only in the pair it opens. That pair is found by scanning ever longer prefixes of the text, so finding it costs about as much as the text it holds, instead of a scan of the rest of the line after every match. On a line of 4,000 `user:ab**(x)** ` it imports in about the time the same line with a space before each `**` took before this change. The remaining growth with line length is core `splitText`, as on main. Export ended a bare URL at any JavaScript whitespace when deciding whether to spoil it, but U+000B, U+2028, U+2029 and U+FEFF are letters for CommonMark, so beside a marker they go out as references, which GFM readers keep in the link: plain `see `, bold `http://x.co/`, then U+2028 and `x` exported as `see **http://x.co/**
x`, which `@lexical/mdast` read as one link with the bold lost. A character written as a reference now counts as part of the URL, so this exports as `see **http://x.co/**&meta#8232;x`. The changeset now gives the import fixes and the export changes paragraphs of their own, and its `Verify:` paragraph names the export snapshots. ## Test plan Command: `pnpm exec vitest run --project unit packages/lexical-markdown/src/__tests__/unit/LexicalMarkdown.test.ts -t "whose syntax has a letter"`, and `-t "letter only for CommonMark"` ### Before ``` × reads formatting after a text match whose syntax has a letter beside it 49ms × reads formatting before a text match whose syntax has a letter beside it 4ms × reads formatting in italic after a text match whose syntax has a letter beside it 4ms AssertionError: expected [ Array(2) ] to deep equally contain [ '(admin)', 1 ] AssertionError: expected [ Array(2) ] to deep equally contain [ '(admin)', 1 ] AssertionError: expected [ [ 'bob', +0 ], [ '*“a”*', +0 ] ] to deep equally contain [ '“a”', 2 ] Tests 3 failed | 782 skipped (785) × exports formatting beside a URL before a character that is a letter only for CommonMark, which both importers read back 33ms AssertionError: expected 'see **http://x.co/**
x' to be 'see **http://x.co/**&meta#8232;x' // Object.is equality ``` ### After ``` $ pnpm exec vitest run --project unit packages/lexical-markdown packages/lexical-mdast packages/lexical-playground/__tests__/unit scripts/__tests__/unit/treeShakingSource.test.ts Test Files 46 passed (46) Tests 1603 passed (1603) ``` The prefix search was compared with a full scan of the rest after every match on 47,000 random lines of delimiters, code spans, escapes and a letter-ending text match, with no differences. Round trips of 20,000 random paragraphs with links, bare URLs, emails and U+2028 or U+FEFF found none that main reads back correctly and this branch does not, in either importer. Co-Authored-By: Claude Opus 5.5 <[email protected]>
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
The "Custom Nodes" steps in AGENTS.md were written before
$configserialization schemas. They only tell agents to implement$config(),createDOM()andupdateDOM(), so agents still hand-writeafterCloneFromandexportJSON.The rewritten steps say:
nodeSchemapassed as$config'sjson. UsewithFieldfor properties stored in a field, and initialize those fields.clone,importJSON,exportJSON,updateFromJSONorafterCloneFromfor schema properties, because$configderives them. A field left out of the schema is lost on the next clone.DOMImportExtension.importDOM()is not deprecated yet, but its deprecation is planned.The section also links the schema and cloning docs.
Test plan
Before
Documentation only.
AGENTS.mdtold agents to implement only$config(),createDOM()andupdateDOM().After
🤖 Generated with Claude Code
https://claude.ai/code/session_015MPoHNJUZoAgRDoWFDvqxr