Skip to content

[lexical-mdast][lexical-website] Bug Fix: Write only the literals from the first one that would read back differently in another form - #9970

Merged
potatowagon merged 5 commits into
meta:mainfrom
mayrang:fix/mdast-literal-first-mismatch
Nov 26, 2026
Merged

potatowagon merged 5 commits into
meta:mainfrom
mayrang:fix/mdast-literal-first-mismatch

Conversation

@mayrang

@mayrang mayrang commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Follow-ups from the automated review of #9965:

  • When one literal in a paragraph, heading or table cell would read back differently, every literal in it was written in resource or autolink form. So typing y right after the third of see www.a.example, www.b.example and www.c.example rewrote all three. Now only the literals from the first one that breaks are written again, and the container is read once more (skipped if that was all of them). If it still breaks, every literal in it is written again, as before. That last step is there because links are matched in order: in xwww.example.com and www.example.com the second link is taken for the first, so writing the second one again changes nothing.
  • The markdown-mdast docs now list such a literal among the forms that are normalized. They also say that the check only covers the paragraph, heading or table cell the literal is written in, so a letter that a contributed paragraph handler appends after it is not checked, as on main.
  • The changeset says what this means for contributed handlers: inline handlers run again each time a container is written again, and a contributed root handler runs inside the package's own, with the state as this.

From this PR's own automated review: a literal right after a code span or ! was kept bare, because GFM's transform reads it back as the same link. But micromark starts no literal there, so it came back with no source position and no link style, and the next export wrote it in resource form. main has the same gap when nothing else in the paragraph breaks. Now a link read back with no position gets its own key, and only its literal is written again.

Changeset

An edit to the pending mdast-literal-neighbours changeset; no new one.

Test plan

Before

TZ=UTC pnpm vitest run --project unit packages/lexical-mdast/src/__tests__/unit/MdastImportExport.test.ts with MdastExport.ts from main:

× writes a literal in resource form when it would not read back bare: `!` before
× writes only the literals from the first that would read back differently
× writes every literal from the first that would read back differently
× writes a literal after a code span in resource form: the next literal keeps its bare form
× writes a literal after a code span in resource form: a letter after it
× reads a container back once when it writes again a literal that only GFM's transform links
× reads a container back once when it writes again a literal that only GFM's transform links, beside a link
AssertionError: expected '!www.example.com' to be '\![www.example.com](http://www.exampl…' // Object.is equality
AssertionError: expected 'see [www.a.example](http://www.a.exam…' to be 'see www.a.example, www.b.example and …' // Object.is equality
AssertionError: expected 'see [www.a.example](http://www.a.exam…' to be 'see www.a.example, [www.b.example](ht…' // Object.is equality
AssertionError: expected '`x`www.a.example and www.b.example' to be '`x`[www.a.example](http://www.a.examp…' // Object.is equality
AssertionError: expected '`x`[www.a.example](http://www.a.examp…' to be '`x`[www.a.example](http://www.a.examp…' // Object.is equality
AssertionError: expected 'so !www.example.com' to be 'so \![www.example.com](http://www.exa…' // Object.is equality
AssertionError: expected 'so [a](http://a.example) !www.example…' to be 'so [a](http://a.example) \![www.examp…' // Object.is equality
Tests  7 failed | 189 passed (196)

After

$ TZ=UTC pnpm vitest run --project unit packages/lexical-mdast/src/__tests__/unit/MdastImportExport.test.ts
Tests  196 passed (196)

$ pnpm run test-unit
Test Files  1027 passed | 6 skipped (1033)
Tests  40435 passed | 423 expected fail | 174 skipped (41032)

pnpm run tsc, pnpm run tsc-test, pnpm run flow (0 errors), pnpm run prettier, pnpm exec eslint on the changed files, pnpm run build and pnpm run check-changesets pass. Writing every literal again, or starting after the first one that changed, fails writes only the literals from the first that would read back differently; writing only the first one that changed, or starting from the last one that changed, fails writes every literal from the first that would read back differently; not reading the container back a second time fails writes a literal in resource form when it would not read back bare: a second literal with the same text; reading it back a second time when every literal was written again fails reads a container back once when it writes again a literal that a letter after it breaks. Counting a link read back with no position as reading back fails writes a literal after a code span in resource form: the next literal keeps its bare form, and writing every literal from it on fails the same test. Across 3,000 fuzzed paragraphs with two to four literals and random neighbours, each exported in both exportPunctuation modes, all 6,000 read back as imported, as on main; micromark reads 1,472 more links in them than in main's output, and none fewer.

…m the first one that would read back differently in another form

## Description

Follow-ups from the automated review of meta#9965:

- When one literal in a paragraph, heading or table cell would read back differently, every literal in it was written in resource or autolink form, so typing `y` right after the third of `see www.a.example, www.b.example and www.c.example` rewrote all three. Now only the literals from the first link that does not read back as written are written again. The container is then read once more, unless that was every literal in it, and if it still does not read back, every literal in it is written again as before. Links are matched in order, so a link that reads back can stand in for an earlier literal with the same text that does not: in `xwww.example.com and www.example.com` the second link is taken for the first, and writing the second one again changes nothing.
- The markdown-mdast docs now list such a literal among the forms that are normalized. They also say that the check only covers the paragraph, heading or table cell the literal is written in, so a letter that a contributed `paragraph` handler appends after it is not checked, as on `main`.
- The changeset says what this means for contributed handlers: inline handlers run again each time a container is written again, and a contributed `root` handler runs inside the package's own, with the state as `this`.

## Changeset

An edit to the pending `mdast-literal-neighbours` changeset; no new one.

## Test plan

### Before

`TZ=UTC pnpm vitest run --project unit packages/lexical-mdast/src/__tests__/unit/MdastImportExport.test.ts` with `MdastExport.ts` from `main`:

```
× writes only the literals from the first that would read back differently
× writes every literal from the first that would read back differently
AssertionError: expected 'see [www.a.example](http://www.a.exam…' to be 'see www.a.example, www.b.example and …' // Object.is equality
AssertionError: expected 'see [www.a.example](http://www.a.exam…' to be 'see www.a.example, [www.b.example](ht…' // Object.is equality
Tests  2 failed | 188 passed (190)
```

### After

```
$ TZ=UTC pnpm vitest run --project unit packages/lexical-mdast/src/__tests__/unit/MdastImportExport.test.ts
Tests  190 passed (190)

$ pnpm run test-unit
Test Files  1027 passed | 6 skipped (1033)
Tests  40429 passed | 423 expected fail | 174 skipped (41026)
```

`pnpm run tsc`, `pnpm run tsc-test`, `pnpm run flow` (0 errors), `pnpm run prettier`, `pnpm exec eslint` on the changed files, `pnpm run build` and `pnpm run check-changesets` pass. Writing every literal again, or starting after the first one that changed, fails `writes only the literals from the first that would read back differently`; writing only the first one that changed, or starting from the last one that changed, fails `writes every literal from the first that would read back differently`; not reading the container back a second time fails `writes a literal in resource form when it would not read back bare: a second literal with the same text`; reading it back a second time when every literal was written again fails `reads a container back once when its first literal is written again`. Across 3,000 fuzzed paragraphs with two to four literals and random neighbours, each exported in both `exportPunctuation` modes, every one of the 1,640 exports that changed has fewer literals written in another form, and all 6,000 read back as imported, as on `main`.
@vercel

vercel Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
lexical Ready Ready Preview Nov 23, 2026 9:28am UTC
lexical-playground Ready Ready Preview Nov 23, 2026 9:28am UTC

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Nov 23, 2026
@rootnode-bot

rootnode-bot Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

AI review status for this pull request.

Review status Updated
🟢 Reviewed (for maintainers only) Nov 23, 2026, 9:45 AM UTC

@pkg-pr-new

pkg-pr-new Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
lexical

npm i https://pkg.pr.new/lexical@9970

@lexical/a11y

npm i https://pkg.pr.new/@lexical/a11y@9970

@lexical/clipboard

npm i https://pkg.pr.new/@lexical/clipboard@9970

@lexical/code

npm i https://pkg.pr.new/@lexical/code@9970

@lexical/code-core

npm i https://pkg.pr.new/@lexical/code-core@9970

@lexical/code-prism

npm i https://pkg.pr.new/@lexical/code-prism@9970

@lexical/code-shiki

npm i https://pkg.pr.new/@lexical/code-shiki@9970

@lexical/compiler

npm i https://pkg.pr.new/@lexical/compiler@9970

@lexical/devtools-core

npm i https://pkg.pr.new/@lexical/devtools-core@9970

@lexical/dragon

npm i https://pkg.pr.new/@lexical/dragon@9970

@lexical/eslint-plugin

npm i https://pkg.pr.new/@lexical/eslint-plugin@9970

@lexical/extension

npm i https://pkg.pr.new/@lexical/extension@9970

@lexical/fast-check

npm i https://pkg.pr.new/@lexical/fast-check@9970

@lexical/file

npm i https://pkg.pr.new/@lexical/file@9970

@lexical/hashtag

npm i https://pkg.pr.new/@lexical/hashtag@9970

@lexical/headless

npm i https://pkg.pr.new/@lexical/headless@9970

@lexical/history

npm i https://pkg.pr.new/@lexical/history@9970

@lexical/html

npm i https://pkg.pr.new/@lexical/html@9970

@lexical/internal

npm i https://pkg.pr.new/@lexical/internal@9970

@lexical/link

npm i https://pkg.pr.new/@lexical/link@9970

@lexical/list

npm i https://pkg.pr.new/@lexical/list@9970

@lexical/mark

npm i https://pkg.pr.new/@lexical/mark@9970

@lexical/markdown

npm i https://pkg.pr.new/@lexical/markdown@9970

@lexical/mdast

npm i https://pkg.pr.new/@lexical/mdast@9970

@lexical/offset

npm i https://pkg.pr.new/@lexical/offset@9970

@lexical/overflow

npm i https://pkg.pr.new/@lexical/overflow@9970

@lexical/plain-text

npm i https://pkg.pr.new/@lexical/plain-text@9970

@lexical/react

npm i https://pkg.pr.new/@lexical/react@9970

@lexical/rich-text

npm i https://pkg.pr.new/@lexical/rich-text@9970

@lexical/selection

npm i https://pkg.pr.new/@lexical/selection@9970

@lexical/table

npm i https://pkg.pr.new/@lexical/table@9970

@lexical/tailwind

npm i https://pkg.pr.new/@lexical/tailwind@9970

@lexical/text

npm i https://pkg.pr.new/@lexical/text@9970

@lexical/utils

npm i https://pkg.pr.new/@lexical/utils@9970

@lexical/y

npm i https://pkg.pr.new/@lexical/y@9970

@lexical/yjs

npm i https://pkg.pr.new/@lexical/yjs@9970

commit: 1576d4f

@rootnode-bot rootnode-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this looks good. Writing only the literals from the first one that breaks, and falling back to every literal for the xwww.example.com and www.example.com case, reads correctly. The two new tests fail on main and pass here. Two optional, non-blocking suggestions:

  1. A literal kept bare after a code span, an entity or ! is respelled on the next save (packages/lexical-mdast/src/MdastExport.ts:299). The partial rewrite is accepted when every link reads back with the same text and URL. But the GFM transform also recovers a literal after a code span, a character reference, ! or ), and a link found that way has no source position, so $importLink stores no mdastLinkStyle (handlers.ts:455-461) and the next export writes it in resource form. To reproduce: import www.a.example and www.b.example, then add inline code x before the first link and y after the second. This branch exports `x`www.a.example and [www.b.example](http://www.b.example)y, and exporting the reimported document gives `x`[www.a.example](http://www.a.example) and [www.b.example](http://www.b.example)y. main writes the resource form on the first export. A reader that follows the GFM spec may not link the bare form at all, since extended autolinks are only recognized at the start of a line, after whitespace, or after *, _, ~ or (. main already has this gap when nothing else in the container breaks; this change just reaches it more often. One option is to give a link with no position a key that never matches in parse (MdastExport.ts:1589), so such a literal is written in resource form as before. The docs page packages/lexical-website/docs/serialization/markdown-mdast.md ("Round-trips are close, not exact") lists link style among what export preserves, which is the contract involved.

  2. Assert the round trip in the new tests (packages/lexical-mdast/src/__tests__/unit/MdastImportExport.test.ts:1371 and :1398). They check the first export only. The table-driven test above them also reimports the output and checks a stable second export (:1222-1227). Doing the same here, with the code-span case from point 1 added, would pin the round trip.

Automated review (maintainer link)

…form where only GFM's transform reads it back as a link

## Description

From the automated review of this PR: a literal right after a code span or `!` was kept bare, because GFM's transform reads it back as the same link. But micromark starts no literal there, so the link that comes back has no source position, the import records no link style for it, and the next export writes it in resource form. With `` `x` `` before the first of `www.a.example and www.b.example` and `y` after the second, the first export was `` `x`www.a.example and [www.b.example](http://www.b.example)y `` and the second `` `x`[www.a.example](http://www.a.example) and … ``, where `main` wrote the resource form at once. `main` has the same gap when nothing else in the container breaks.

The container check now tells such a link apart: a link read back with no position gets its own key, and its literal is written again on its own, whatever its text and URL read back as. From the first link with a position that does not read back, every literal is written again as before. When no literal is left bare, the container is not read a second time. Giving such a link a key that never matches would also fix it, but it then writes every literal after it again too: more literals than this in 1,262 of 6,000 fuzzed exports, two or more in 492.

The two tests for literals beside stand-ins put `⸀` right before the literal, where the literal is now written in resource form either way, so they no longer caught a nested export that does not restore the outer one's stand-ins. They now put it in the literal's path, `(www.example.com/a⸀b)`. The tests for the first changed literal also read the output back, as the table-driven tests do.

## Test plan

### Before

`TZ=UTC pnpm vitest run --project unit packages/lexical-mdast/src/__tests__/unit/MdastImportExport.test.ts` with `MdastExport.ts` from the previous commit:

```
× writes a literal in resource form when it would not read back bare: `!` before
× writes a literal after a code span in resource form: the next literal keeps its bare form
× writes a literal after a code span in resource form: a letter after it
× writes a literal after a code span in resource form: before another literal that does not read back
× reads a container back once when it writes again a literal that only GFM's transform links
× reads a container back once when it writes again a literal that only GFM's transform links, beside a link
AssertionError: expected '!www.example.com' to be '\![www.example.com](http://www.exampl…' // Object.is equality
AssertionError: expected '`x`www.a.example and www.b.example' to be '`x`[www.a.example](http://www.a.examp…' // Object.is equality
AssertionError: expected '`x`[www.a.example](http://www.a.examp…' to be '`x`[www.a.example](http://www.a.examp…' // Object.is equality
AssertionError: expected '`x`www.a.example and [www.b.example](…' to be '`x`[www.a.example](http://www.a.examp…' // Object.is equality
AssertionError: expected 'so !www.example.com' to be 'so \![www.example.com](http://www.exa…' // Object.is equality
AssertionError: expected 'so [a](http://a.example) !www.example…' to be 'so [a](http://a.example) \![www.examp…' // Object.is equality
Tests  6 failed | 190 passed (196)
```

### After

```
$ TZ=UTC pnpm vitest run --project unit packages/lexical-mdast/src/__tests__/unit/MdastImportExport.test.ts
Tests  196 passed (196)

$ pnpm run test-unit
Test Files  1027 passed | 6 skipped (1033)
Tests  40435 passed | 423 expected fail | 174 skipped (41032)
```

`pnpm run tsc`, `pnpm run tsc-test`, `pnpm run flow` (0 errors), `pnpm run prettier`, `pnpm exec eslint` on the changed files, `pnpm run build` and `pnpm run check-changesets` pass. Counting a link read back with no position as reading back, or not writing its literal again, fails `writes a literal after a code span in resource form: the next literal keeps its bare form`; writing every literal from it on fails the same test; treating it so only when its text and URL read back fails `writes a literal after a code span in resource form: a letter after it`; leaving the container as it was when only such a link is found also fails `` writes a literal in resource form when it would not read back bare: `!` before ``; reading it back a second time when that literal was the only one fails `reads a container back once when it writes again a literal that only GFM's transform links`, and doing so beside a resource link also fails `reads a container back once when it writes again a literal that only GFM's transform links, beside a link`. With the stand-in tests as they were, not restoring an outer export's stand-ins after a nested one passed every test; it now fails `checks a literal exported after another export wrote with stand-ins`. Across 3,000 fuzzed paragraphs with two to four literals and random neighbours, each exported in both `exportPunctuation` modes, all 6,000 exports read back as imported. 1,804 change: in 1,472 one more literal is written in another form, and micromark reads one more link than in the previous commit's output; in 332 one to three fewer are. Skipping such links on the second read changes none of the 6,000.

@rootnode-bot rootnode-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this looks good. Rewriting only the literals from the first one that would read back differently keeps the earlier links as the author wrote them. Keying a link that comes back with no source position (packages/lexical-mdast/src/MdastExport.ts:1628-1630) also removes the one-save respelling of a literal right after a code span or !. Both follow-ups from the earlier review are addressed: the two new tests reimport the output and check the second export, and the code-span cases cover an earlier literal that only the transform links. The 7 new tests fail against main's MdastExport.ts and pass here.

One optional, non-blocking suggestion:

  • packages/lexical-website/docs/serialization/markdown-mdast.md:126-128 and the last paragraph of .changeset/mdast-literal-neighbours.md give the trigger as "right after a code span or !, say". It also fires after ., ), &, <, 、 or an ideographic space. The GFM spec's autolink extension starts a literal only "at the beginning of a line, after whitespace, or any of the delimiting characters *, _, ~, and (", while remark's transform links one after any punctuation or whitespace. Stating that rule once would tell readers why typing . before a link changes how it is written.

Automated review (maintainer link)

…ral in the mdast docs and changeset

## Description

From the automated review of this PR: the docs and the changeset gave the case where a bare literal is written in another form as "right after a code span or `!`, say", but it also happens after `.`, `)`, `&`, `<`, `、`, an ideographic space and most other characters. Both now state the rule once: GFM starts a literal only at the start of a line or after whitespace, `*`, `_`, `~` or `(`, so anywhere else only its transform links one. No code changes.

## Test plan

### After

```
$ pnpm exec prettier --check packages/lexical-website/docs/serialization/markdown-mdast.md .changeset/mdast-literal-neighbours.md
All matched files use Prettier code style!

$ pnpm run check-changesets
Changeset check passed: 197 pending changeset(s) valid.
```

Importing `see www.example.com` and typing one character right before the link, the export keeps it bare after a space, `*`, `_`, `~` or `(`, and writes `[www.example.com](http://www.example.com)` after `.`, `)`, `&`, `<`, `、`, an ideographic space, `"`, `:` or `!`; each output exports the same again.

@rootnode-bot rootnode-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me. The partial rewrite is only kept when the paragraph, heading or table cell reads back with every link intact, and otherwise falls back to today's output, and keying a link that comes back with no source position separately removes the one-save respelling after a code span or !. The new tests fail against main's MdastExport.ts and pass here, and each of the four mechanisms (the position-less key, the second read, the from-the-first slice, the skipped re-read) is pinned by at least one of them.

One optional, non-blocking suggestion:

  • packages/lexical-website/docs/serialization/markdown-mdast.md:128-131 and .changeset/mdast-literal-neighbours.md:9: the sentence "GFM starts a literal only at the start of a line or after whitespace, *, _, ~ or (" follows the GFM spec's general wording for extended autolinks, but micromark-extension-gfm-autolink-literal, which this package parses with, applies that restriction to www. literals only (previousWww, which also allows [ and ]). A https:// literal starts after anything but an ASCII letter (previousProtocol), and an email literal after anything but / or an address character (previousEmail). So on this branch !https://example.com, `x`https://example.com and [email protected] keep their bare form, and typing . or ! before such a link does not change how it is written. Scoping the sentence would make both the docs page and the changeset exact, for example: "GFM starts a www. literal only at the start of a line or after whitespace, *, _, ~, (, [ or ], so after ., !, a code span and most other characters only its transform links one." This refines the wording suggested in the earlier review comment, which took it from the spec. No code change is needed, since the export reads each container back rather than relying on the rule.

Automated review (maintainer link)

…teral starts to www. literals

## Description

From the automated review of this PR: the docs and the changeset said GFM starts a literal only at the start of a line or after whitespace, `*`, `_`, `~` or `(`. micromark, which `@lexical/mdast` parses with, applies that rule to `www.` literals only, and also lets one start after `[` or `]`; a `https://` literal starts after anything but an ASCII letter, and an email literal after anything but `/` or an address character. Both now state the rule for `www.` literals. No code changes.

## Test plan

### After

```
$ pnpm exec prettier --check packages/lexical-website/docs/serialization/markdown-mdast.md .changeset/mdast-literal-neighbours.md
All matched files use Prettier code style!

$ pnpm run check-changesets
Changeset check passed: 197 pending changeset(s) valid.
```

Importing `see <link>` and typing one character right before the link: after `!`, a code span or `.`, `www.example.com` is written as `[www.example.com](http://www.example.com)`, while `https://example.com` and `[email protected]` stay bare after `!` and a code span; after `]` all three stay bare. `previousWww`, `previousProtocol` and `previousEmail` in `micromark-extension-gfm-autolink-literal` give the same rules.

@rootnode-bot rootnode-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me. Scoping the GFM rule to www. literals, with [ and ] added, in both markdown-mdast.md and the changeset now matches what micromark-extension-gfm-autolink-literal does (an exported [ is always escaped to \[, which opens no label, so a literal right after it stays bare). The export change itself is as in the last round: a partial rewrite is kept only when the paragraph, heading or table cell reads back with every link intact and none found only by the transform, and otherwise falls back to today's output. The new tests fail against main's MdastExport.ts and pass here, and each mechanism they cover (the position-less key, the second read, the from-the-first slice, the skipped re-read) is pinned by at least one of them.

One optional, non-blocking nit, not worth a round on its own:

  • packages/lexical-website/docs/serialization/markdown-mdast.md:130-131: "after ., !, a code span and most other characters only its transform links one". The transform (previous in mdast-util-gfm-autolink-literal) links only at the start of a text node or after whitespace or punctuation, so after a letter or digit neither it nor micromark links the literal: xwww.example.com and 7www.example.com parse with no link at all, while .www.example.com, !www.example.com and `c`www.example.com come back as transform-only links. The export writes the resource form either way, so only the explanation is off. If you touch the sentence again, for example: "so after other punctuation such as . or !, after other whitespace or after a code span only its transform links one, and after a letter or digit neither does." This refines the wording suggested in the earlier review comment.

Automated review (maintainer link)

… literal right after a letter or digit

## Description

From the automated review of this PR: the docs said that after `.`, `!`, a code span "and most other characters" only GFM's transform links a `www.` literal. After a letter or digit neither micromark nor the transform links one, since `previous` in `mdast-util-gfm-autolink-literal` only links at the start of a text node or after whitespace or punctuation. The sentence now names punctuation, other whitespace and a code span, and says that after a letter or digit neither does. The changeset only mentions `.` and `!`, so it stays. No code changes.

## Test plan

### After

```
$ pnpm exec prettier --check packages/lexical-website/docs/serialization/markdown-mdast.md
All matched files use Prettier code style!
```

Parsing with the `mdast-util-from-markdown`, `micromark-extension-gfm-autolink-literal` and `mdast-util-gfm-autolink-literal` versions this package uses: `xwww.example.com`, `7www.example.com` and `éwww.example.com` give no link; `.www.example.com`, `!www.example.com`, `` `c`www.example.com `` and the literal after an ideographic or no-break space give a link with no source position (the transform's); `a www.example.com` gives a link with a position (micromark's).

@rootnode-bot rootnode-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me. Thanks for working through the follow-ups.

  • The narrower rewrite in checkLiterals (packages/lexical-mdast/src/MdastExport.ts:276-327) holds up. Both acceptance checks (:293, :321) now need every link to come back with a source position and the same key, which is stricter than before. The '\0' key for a link read back with no position (:1628-1630) can never equal a linkKey, and when the container still does not read back, the fallback respells every literal as main does.
  • The new cases in MdastImportExport.test.ts fail against main's exporter and pass here. expectLiteralRoundTrip checks the reimported runs and a stable second export, which pins the round trip the partial rewrite relies on.
  • The www. start rule in markdown-mdast.md and in the changeset matches previousWww in micromark-extension-gfm-autolink-literal and previous in mdast-util-gfm-autolink-literal, and the earlier docs-wording threads are addressed.

No further changes requested from my side.

Automated review (maintainer link)

@potatowagon
potatowagon added this pull request to the merge queue Nov 26, 2026
Merged via the queue into meta:main with commit d8d0c91 Nov 26, 2026
61 checks passed

This branch was successfully deployed

2 active deployments
Preview – lexical — 1576d4f5 Deployed Nov 23, 2026 by vercel[bot]
Preview – lexical-playground — 1576d4f5 Deployed Nov 23, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants