Skip to content

[lexical-mdast] Bug Fix: Escape the dot of www. so the characters after it import as typed - #9956

Merged
potatowagon merged 5 commits into
meta:mainfrom
mayrang:www-reference
Nov 22, 2026
Merged

potatowagon merged 5 commits into
meta:mainfrom
mayrang:www-reference

Conversation

@mayrang

@mayrang mayrang commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

Description

With MdastAutolinkLiteralExtension (part of MdastGfmExtension), export escapes the . of www. only before an ASCII letter or digit, _, - or . as typed. What the export writes after it can still be something else: a reference when the character is non-ASCII and beside formatting, an escape when it is punctuation, or the marker of a format that starts or ends there, or of a link. micromark starts a literal on www. before any of these and reads it as part of the link, so the characters change on import. www.世 before bold ! is written as www.世**!** and read back as a link to http://www.&#x4E16, then ; and !; before bold 。 the link takes the ** and the bold is lost; www._x is read back as a link to http://www.\_x; www. before bold x is written as www.**x** and read back as a link to http://www.**x, then **. GitHub renders www.世**!** the same way.

This adds an unsafe rule to the extension that escapes the . after www (any case) in text, whatever follows it. The rule has no after, because mdast-util-to-markdown skips a rule that has an after where a rule with no condition escapes the next character, as one does *. The import may still link the decoded text, but its characters are the ones typed. Plain www.example.com was written as www\.example.com already. The export also joins adjacent text siblings before serializing, so a www that an inline element with no export rule (a MarkNode) splits is escaped as one text, and so is a 1 before a mark of . x, which would otherwise start an ordered list; a text with anything but its value, such as data or a position an export rule set, is kept apart. The escape is also written where it is not needed, such as see www\. then, which imports as before.

Changeset

.changeset/mdast-www-dot-escape.md (@lexical/mdast patch).

Test plan

Before

TZ=UTC pnpm vitest run --project unit packages/lexical-mdast/src/__tests__/unit/MdastPunctuation.test.ts with the new tests and the source of main:

 FAIL  |unit| packages/lexical-mdast/src/__tests__/unit/MdastPunctuation.test.ts > Mdast punctuation modes > keeps the characters after `www.` in [["www.世",0],["!",1]]
AssertionError: expected 'www.世**!**' to be 'www\.世**!**' // Object.is equality
...
      Tests  17 failed | 106 passed (123)

Importing that export on main (both punctuation modes) gives LINK(http://www.&#x4E16)["www.&#x4E16",0] [";",0] ["!",1].

After

$ TZ=UTC pnpm vitest run --project unit packages/lexical-mdast/src/__tests__/unit/MdastPunctuation.test.ts packages/lexical-mdast/src/__tests__/unit/MdastImportExport.test.ts
      Tests  242 passed (242)
$ TZ=UTC pnpm run test-unit
 Test Files  1021 passed | 6 skipped (1027)
      Tests  40261 passed | 423 expected fail | 174 skipped (40858)
$ VITEST_BROWSER=chromium,firefox,webkit TZ=UTC pnpm vitest run --project browser dev-examples/mdast-editor/src/__tests__/browser
 Test Files  12 passed (12)
      Tests  90 passed (90)

These exited 0 with this output, apart from a Browserslist data-age warning from eslint and build:

$ tsc
$ tsc -p ./tsconfig.test.json
$ prettier --list-different .
$ pnpm exec eslint packages/lexical-mdast/src/MdastExtension.ts packages/lexical-mdast/src/__tests__/unit/MdastPunctuation.test.ts packages/lexical-mdast/src/__tests__/unit/MdastImportExport.test.ts
$ node scripts/build.mjs
$ node ./scripts/changesets/check.mjs
Changeset check passed: 192 pending changeset(s) valid.

The browser tests above are the ones that use @lexical/mdast. No e2e test was run: the playground does not use @lexical/mdast.

…er it import as typed

## Description

With `MdastAutolinkLiteralExtension` (part of `MdastGfmExtension`), export escapes the `.` of `www.` only before an ASCII letter or digit, `_`, `-` or `.` as typed. What the export writes after it can still be something else: a reference when the character is non-ASCII and beside formatting, an escape when it is punctuation, or the marker of a format that starts or ends there, or of a link. micromark starts a literal on `www.` before any of these and reads it as part of the link, so the characters change on import. `www.世` before bold `!` is written as `www.世**!**` and read back as a link to `http://www.&#x4E16`, then `;` and `!`; before bold `。` the link takes the `**` and the bold is lost; `www._x` is read back as a link to `http://www.\_x`; `www.` before bold `x` is written as `www.**x**` and read back as a link to `http://www.**x`, then `**`. GitHub renders `www.世**!**` the same way.

This adds an unsafe rule to the extension that escapes the `.` after `www` (any case) in text, whatever follows it. The rule has no `after`, because mdast-util-to-markdown skips a rule that has an `after` where a rule with no condition escapes the next character, as one does `*`. The import may still link the decoded text, but its characters are the ones typed. Plain `www.example.com` was written as `www\.example.com` already. The escape is also written where it is not needed, such as `see www\. then`, which imports as before.

## Changeset

`.changeset/mdast-www-dot-escape.md` (`@lexical/mdast` patch).

## Test plan

### Before

`TZ=UTC pnpm vitest run --project unit packages/lexical-mdast/src/__tests__/unit/MdastPunctuation.test.ts` with the new tests and the source of `main`:

```
 FAIL  |unit| packages/lexical-mdast/src/__tests__/unit/MdastPunctuation.test.ts > Mdast punctuation modes > keeps the characters after `www.` in [["www.世",0],["!",1]]
AssertionError: expected 'www.世**!**' to be 'www\.世**!**' // Object.is equality
...
      Tests  9 failed | 101 passed (110)
```

Importing that export on `main` (both punctuation modes) gives `LINK(http://www.&#x4E16)["www.&#x4E16",0] [";",0] ["!",1]`.

### After

```
$ TZ=UTC pnpm vitest run --project unit packages/lexical-mdast/src/__tests__/unit/MdastPunctuation.test.ts packages/lexical-mdast/src/__tests__/unit/MdastImportExport.test.ts
      Tests  229 passed (229)
$ TZ=UTC pnpm run test-unit
 Test Files  1021 passed | 6 skipped (1027)
      Tests  40248 passed | 423 expected fail | 174 skipped (40845)
$ VITEST_BROWSER=chromium,firefox,webkit TZ=UTC pnpm vitest run --project browser dev-examples/mdast-editor/src/__tests__/browser
 Test Files  12 passed (12)
      Tests  90 passed (90)
```

These exited 0 with this output, apart from a Browserslist data-age warning from eslint and build:

```
$ tsc
$ tsc -p ./tsconfig.test.json
$ prettier --list-different .
$ pnpm exec eslint packages/lexical-mdast/src/MdastExtension.ts packages/lexical-mdast/src/__tests__/unit/MdastPunctuation.test.ts packages/lexical-mdast/src/__tests__/unit/MdastImportExport.test.ts
$ node scripts/build.mjs
$ node ./scripts/changesets/check.mjs
Changeset check passed: 192 pending changeset(s) valid.
```

The browser tests above are the ones that use `@lexical/mdast`. No e2e test was run: the playground does not use `@lexical/mdast`.
@vercel

vercel Bot commented Nov 20, 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 20, 2026 10:33pm UTC
lexical-playground Ready Ready Preview Nov 20, 2026 10:33pm 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 20, 2026
@rootnode-bot

rootnode-bot Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

AI review status for this pull request.

Review status Updated
🟢 Reviewed (for maintainers only) Nov 20, 2026, 10:48 PM UTC

@pkg-pr-new

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

Copy link
Copy Markdown
lexical

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

@lexical/a11y

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

@lexical/clipboard

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

@lexical/code

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

@lexical/code-core

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

@lexical/code-prism

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

@lexical/code-shiki

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

@lexical/compiler

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

@lexical/devtools-core

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

@lexical/dragon

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

@lexical/eslint-plugin

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

@lexical/extension

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

@lexical/fast-check

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

@lexical/file

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

@lexical/hashtag

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

@lexical/headless

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

@lexical/history

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

@lexical/html

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

@lexical/internal

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

@lexical/link

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

@lexical/list

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

@lexical/mark

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

@lexical/markdown

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

@lexical/mdast

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

@lexical/offset

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

@lexical/overflow

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

@lexical/plain-text

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

@lexical/react

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

@lexical/rich-text

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

@lexical/selection

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

@lexical/table

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

@lexical/tailwind

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

@lexical/text

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

@lexical/utils

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

@lexical/y

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

@lexical/yjs

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

commit: 9afc809

@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, and thanks for the thorough reproduction. Escaping the . of www. in phrasing text, outside links and labels, matches how micromark's autolink-literal grammar works: it starts a literal after www. whatever character follows, so no after condition could list every case. Link titles and fence info strings stay unescaped, and the new cases fail against main and pass here.

Two optional, non-blocking suggestions:

  • .changeset/mdast-www-dot-escape.md:5: most editors get this extension through MdastGfmExtension, so naming that bundle in the summary would help changelog readers recognise the change. The worked example could also move into the Verify: paragraph, so the summary stays one short line (see .changeset/README.md).
  • packages/lexical-mdast/src/__tests__/unit/MdastPunctuation.test.ts, the table ending at line 979: the old export also loses www. before inline code (see www.`x` now imports as a link that swallows the code span). A row like [['see www.', 0], ['x', code]] would pin that marker too.

Automated review (maintainer link)

Comment thread .changeset/mdast-www-dot-escape.md Resolved
…angeset summary

## Description

Follow-up to the review: the export on `main` also loses `www.` before inline code (``see www.`x` now`` imports as a link to ``http://www.`x` `` and the code format is lost). This adds that case to the `www.` test table, and shortens the changeset summary to one line that names `MdastGfmExtension`, with the example moved into `Verify:`. No source change.

## Changeset

`.changeset/mdast-www-dot-escape.md` (summary and `Verify:` reworded).

## Test plan

### Before

`TZ=UTC pnpm vitest run --project unit packages/lexical-mdast/src/__tests__/unit/MdastPunctuation.test.ts` with the source of `main`:

```
AssertionError: expected 'see www.`x` now' to be 'see www\.`x` now' // Object.is equality
...
      Tests  10 failed | 101 passed (111)
```

### After

```
$ TZ=UTC pnpm vitest run --project unit packages/lexical-mdast/src/__tests__/unit/MdastPunctuation.test.ts packages/lexical-mdast/src/__tests__/unit/MdastImportExport.test.ts
      Tests  230 passed (230)
$ TZ=UTC pnpm run test-unit
 Test Files  1021 passed | 6 skipped (1027)
      Tests  40249 passed | 423 expected fail | 174 skipped (40846)
$ VITEST_BROWSER=chromium,firefox,webkit TZ=UTC pnpm vitest run --project browser dev-examples/mdast-editor/src/__tests__/browser
 Test Files  12 passed (12)
      Tests  90 passed (90)
$ node ./scripts/changesets/check.mjs
Changeset check passed: 192 pending changeset(s) valid.
```

These exited 0 with this output, apart from a Browserslist data-age warning from eslint:

```
$ tsc -p ./tsconfig.test.json
$ prettier --list-different .
$ pnpm exec eslint packages/lexical-mdast/src/__tests__/unit/MdastPunctuation.test.ts
```

@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. Escaping the . of www. in phrasing text, outside links, images and labels, matches how micromark's GFM autolink-literal grammar behaves: it starts a literal at www. and reads through whatever the export writes next, so no after condition could list every case. Link titles and fence info strings are untouched, and the new cases fail against main and pass here. Thanks for adding the inline-code row and moving the worked example into Verify:.

One optional, non-blocking note:

  • packages/lexical-mdast/src/MdastExtension.ts:515: before: '[Ww]{3}' needs all three ws in the string safe() checks, but mdast-util-to-markdown gives a text node only the last character of its previous sibling as before. A www. split across sibling text nodes therefore still goes out unescaped. That happens when an inline element with no export rule of its own, such as a MarkNode, starts or ends inside www. For example, see ww + mark(w.世) + bold ! exports as see www.世**!** and reads back as a link to http://www.&#x4E16, then ;. main does the same, so this is not a regression. A follow-up could join adjacent text siblings before serializing, or the comment above the rule could note the limit.

Automated review (maintainer link)

…ent splits

## Description

Follow-up to the review: an inline element with no export rule of its own, such as a `MarkNode`, exports its children in place, beside the text around it, as separate text nodes. `mdast-util-to-markdown` gives a text only the last character of the one before it to decide its escapes, so the `www` rule does not see a `www` split over them: `see ww` + mark(`w.世`) + bold `!` was still written as `see www.世**!**` and read back as a link to `http://www.&#x4E16`, then `;` and `!`. `main` does the same.

The export now joins each run of adjacent text siblings into one text before serializing, so escapes are decided on the whole text: the rule sees the whole `www`, and `1` before a mark of `. x`, which was written as `1. x` and read back as an ordered list, is written as `1\. x`. A text with anything but its value, such as `data` or a `position` that an export rule set for a handler to read, is kept apart.

## Changeset

`.changeset/mdast-www-dot-escape.md` (summary now names this case).

## Test plan

### Before

`TZ=UTC pnpm vitest run --project unit packages/lexical-mdast/src/__tests__/unit/MdastPunctuation.test.ts` with the new tests and the previous `MdastExport.ts`:

```
 FAIL  |unit| packages/lexical-mdast/src/__tests__/unit/MdastPunctuation.test.ts > Mdast punctuation modes > keeps the characters after a `www.` a mark splits (strict-commonmark)
AssertionError: expected 'see www.世**!**' to be 'see www\.世**!**' // Object.is equality
 FAIL  |unit| packages/lexical-mdast/src/__tests__/unit/MdastPunctuation.test.ts > Mdast punctuation modes > escapes text a mark splits as one text (cjk-friendly)
AssertionError: expected '1. x' to be '1\. x' // Object.is equality
      Tests  7 failed | 116 passed (123)
```

### After

```
$ TZ=UTC pnpm vitest run --project unit packages/lexical-mdast
      Tests  552 passed (552)
$ TZ=UTC pnpm run test-unit
 Test Files  1021 passed | 6 skipped (1027)
      Tests  40261 passed | 423 expected fail | 174 skipped (40858)
```

These exited 0 with this output, apart from a Browserslist data-age warning from eslint and build:

```
$ tsc
$ tsc -p ./tsconfig.test.json
$ node ./scripts/check-flow-types.mjs
Running Flow...
Found 0 errors
$ prettier --list-different .
$ pnpm exec eslint packages/lexical-mdast/src
$ node scripts/build.mjs
$ node ./scripts/changesets/check.mjs
Changeset check passed: 192 pending changeset(s) valid.
```

@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. The new rule escapes the . after www only in phrasing text, so link text, titles, destinations, inline code and fences are untouched, and joining adjacent plain texts before serializing also fixes 1 + a mark of . x, which used to re-import as an ordered list. The new cases in MdastPunctuation.test.ts fail against main and pass here, and the earlier suggestions (the inline-code row, the www split by a mark, the changeset wording) are all addressed.

A few optional, non-blocking suggestions:

  1. Pin the second round trip (optional). The import still links the decoded text (www\.**x** reads back as a link to http://www, then . and bold x), and the next export writes that link as [www](http://www).**x**, which reads back the same. Because mergeRuns compares only characters and formats, a case that exports, imports and exports again would pin that stability.
  2. Mention the join for extension authors (optional). With the join, a custom text handler in toMarkdownExtensions receives one joined text where an inline element with no export rule splits plain text (the "joins a text beside another only with nothing set" cases). One clause in the Verify: paragraph of .changeset/mdast-www-dot-escape.md would tell them; .changeset/README.md asks Verify: to say what people upgrading should test.
  3. Possible follow-up in a separate PR. The same micromark behaviour affects a link imported from a bare literal: the link handler in syntaxToMarkdown writes it as its text (packages/lexical-mdast/src/MdastExport.ts:211-216), so a literal www.example.com followed by bold y exports www.example.com**y** and re-imports as a link to http://www.example.com**y, then **. This happens on main too and is outside this PR's scope; the comment there says the autolink-literal extension keeps the surrounding escaping consistent, which this case shows it does not.

Automated review (maintainer link)

… joined text in the changeset

## Description

Follow-up to the review. The import of `www\.**x**` still links the decoded `www`, and that link has no source syntax to keep, so the next export writes it as `[www](http://www).**x**`, which reads back the same. The `www.` test table gets a column with that second export, and the test checks that it reads back as the same runs and exports the same again. The changeset's `Verify:` paragraph now says that a custom `text` handler in `toMarkdownExtensions` receives adjacent texts with nothing set but their value as one text, such as plain text that an inline element with no export rule splits, or a text that an export rule returns beside other text. No source change.

## Changeset

`.changeset/mdast-www-dot-escape.md` (one sentence added to `Verify:`).

## Test plan

### Before

The new checks pass on the parent commit too, since they pin current behaviour. They fail when `$importLink` in `packages/lexical-mdast/src/handlers.ts` marks a link that has no position as a bare literal, or makes no link for it:

```
      Tests  9 failed | 114 passed (123)
```

With the test file of the parent commit, both changes pass.

### After

```
$ TZ=UTC pnpm vitest run --project unit packages/lexical-mdast
 Test Files  18 passed (18)
      Tests  552 passed (552)
```
@mayrang

mayrang commented Nov 20, 2026

Copy link
Copy Markdown
Collaborator Author

Both added in 43d3874. The www. table now pins the second export ([www](http://www).**x** and so on) and checks that it reads back the same. The Verify: sentence also names a text that an export rule returns, since the join merges that too. The bare literal before formatting (www.example.com**y**) does the same on main, so I'll take it in a separate PR.

@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 to me. The suggestion below is optional and non-blocking.

The new rule in packages/lexical-mdast/src/MdastExtension.ts:512-521 applies only to phrasing text outside links, images and labels. CommonMark §2.4 says "Any ASCII punctuation character may be backslash-escaped", so the extra www\. never changes what a document reads as. It only stops micromark from starting a literal on www. and pulling a following character reference, escape, code span or emphasis marker into the link. Joining plain sibling texts before serializing (MdastExport.ts:892-948) gives the escapes their full context without touching texts that carry data, position or other keys. It also fixes 1 + mark(. x) being written as an ordered list. The tests pin the export, the re-imported characters and the second export in both punctuation modes, and as your test plan shows, they fail on main. Thanks for taking up the earlier suggestions: naming MdastGfmExtension, the inline-code row and the split-www case.

Optional:

  • .changeset/mdast-www-dot-escape.md:5: the summary line is 268 characters. .changeset/README.md asks for a one-line summary describing the change from the user's side. The clause about an inline element splitting the www could move into the paragraph below, which already explains the join. That would leave something like [fix] With MdastGfmExtension or MdastAutolinkLiteralExtension, export escapes the . of www. in text whatever follows it, so the characters after it are read back as typed.

You noted that a literal link written directly before a format marker (www.example.com**y**) behaves the same on main, so a separate PR for it makes sense.

Automated review (maintainer link)

## Description

Follow-up to the review. The changeset summary was 268 characters, with a clause about an inline element splitting the `www`. That clause now opens the paragraph below it, which already explains the join, and the summary keeps only the change as users see it. No source change.

## Changeset

`.changeset/mdast-www-dot-escape.md` (summary shortened, clause moved into the next paragraph).
@mayrang

mayrang commented Nov 20, 2026

Copy link
Copy Markdown
Collaborator Author

Moved in 9afc809; the summary is now 178 characters.

@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 the careful fix.

Escaping the . of www. in text is a plain CommonMark backslash escape (spec §2.4, "Any ASCII punctuation character may be backslash-escaped"), so every reader still reads www., while the GFM www autolink literal can no longer start on it and swallow the character reference, escape, code span, link or emphasis marker that follows. The rule's inConstruct/notInConstruct are the same ones mdast-util-gfm-autolink-literal uses for its own . rule, so link text, titles, destinations and code stay as they were, and leaving out after is the right call given how mdast-util-to-markdown's safe() drops a conditional escape in front of an unconditionally escaped character.

Joining adjacent plain text siblings before serializing (packages/lexical-mdast/src/MdastExport.ts) also reads correctly: texts carrying data, a position or any other key stay apart, $exportToMdast still returns the unjoined tree, and it fixes 1 beside a mark of . x, which used to come back as an ordered list. The new tests check the export, the imported runs and a stable second export in both punctuation modes, and the changeset follows .changeset/README.md, with a Verify: paragraph that also tells custom text handler authors what changed.

Thanks for keeping the literal-link-before-formatting case (www.example.com**y**) for a separate PR, since it behaves the same on main.

Optional, non-blocking: a row with www. in a heading would pin the rule outside paragraphs too; it behaves like a paragraph today.

Automated review (maintainer link)

This branch was successfully deployed

2 active deployments
Preview – lexical — 9afc8095 Deployed Nov 20, 2026 by vercel[bot]
Preview – lexical-playground — 9afc8095 Deployed Nov 20, 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