Skip to content

[lexical-mdast][lexical-website] Bug Fix: Read literal autolinks on import as GitHub comments do - #9990

Merged
etrepum merged 5 commits into
meta:mainfrom
mayrang:chore/mdast-gfm-autolink-literal-2.1.2
Nov 28, 2026
Merged

etrepum merged 5 commits into
meta:mainfrom
mayrang:chore/mdast-gfm-autolink-literal-2.1.2

Conversation

@mayrang

@mayrang mayrang commented Nov 28, 2026 •

Copy link
Copy Markdown
Collaborator

Description

The export writes a URL typed as text with an escape, so that GitHub shows it as text: https://x.com exports as https\://x.com and www.x.com as www\.x.com. The import links both again, because the transform of mdast-util-gfm-autolink-literal finds URL literals in the decoded text, where the escape is gone. GitHub renders comments (POST /markdown with mode: gfm) with URL literals found only in the Markdown as written and email literals also in the decoded text: https\://x.com shows as text there and a\@b.co as a link. The library follows the file mode instead, where https\://x.com links too, so with it a URL typed as text cannot read back as text.

This updates mdast-util-gfm-autolink-literal from ^2.0.1 to ^2.1.2 and reads literal autolinks as GitHub comments do: a www. or http(s):// URL links only where micromark finds it in the source, and an email, mailto: or xmpp: literal links where the library's transform finds it. Before that transform runs, the import puts q in place of the first letter of each www. or http(s):// in the text, so that the transform starts no URL there but reads emails as before, and then puts the letters back. Typed https://x.com and www.x.com now read back as text.

Markdown written elsewhere imports differently where GitHub comments read it differently from the transform: a www. URL right after ., !, " or a code span (see .www.x.com, `code`www.a.example) or one written with a character reference (www.x.com) now imports as text, as GitHub shows it, and an email inside an escaped URL (https\://x.com/[email protected]) now links on its own instead of the whole URL. A URL that GitHub links but micromark does not find in the source now imports as text too: www._x.com. next, where GitHub links www._x.com because cmark-gfm checks the _ of the domain before trimming the ., and www.café_bar.com. Plain URLs and emails import as before. Everything in @lexical/mdast is experimental, and 2.1.2 already changes some imports on its own (CJK before an email, mailto:, a domain that starts with punctuation), but this is still a change for documents written elsewhere, so the changeset lists it.

2.1.2 ships the rule that escapes the . of www. before any character, which #9956 added here, so that rule is removed. 2.1.2 also escapes : after an uppercase P or S, so Markdown FTP://a.co/ ©_a_ now exports as FTP\://a.co/ ©_a_, which cmark-gfm reads as the text and italic that Lexical has, where before it read one link. Two literals after a code span both export in resource form now (`x`[www.a.example](http://www.a.example) and [www.b.example](http://www.b.example)): the first no longer reads back as a link, and the export from #9970 writes every literal from the first one that would read back differently in that form.

Most of the new tests pin an input against what cmark-gfm 0.29.0.gfm.14 links, since each was a case where a simpler version of this change read differently from GitHub. A few replace the library's transform with one that returns pieces that do not line up, to check that the import then keeps the text as it was rather than leave a q in it.

Test plan

Compared by the link texts against cmark-gfm 0.29.0.gfm.14 (-e autolink -e tasklist), which agrees with GitHub comments for these inputs, the import with this change and with 2.1.2 alone:

  • 3 × 30,000 random paragraphs of letters, CJK, punctuation, escapes, references, www, https://, mailto: and @: 29,732 / 29,713 / 29,711 agree with 2.1.2 alone, 29,914 / 29,904 / 29,901 with this change; 2 that agreed no longer do.
  • 6,000 strict and 5,000 CJK-friendly (with MdastHtmlExtension) paragraphs built around escaped URLs and emails in emphasis, links, task lists, headings, quotes and tables: 1,925 and 1,583 agree with 2.1.2 alone, 5,059 and 4,210 with this change; the 12 and 12 that only 2.1.2 got right are emails such as a\@www.x.com\@b.co, where the library's email pattern differs from cmark-gfm.
  • 3,900 typed texts exported and imported again: no URL reads back as a link (1,120 with 2.1.2 alone).

The random comparisons were run with scratch scripts that are not part of this PR. The cases below are pinned in MdastAutolinkLiteral.test.ts, which imports them as text, as text, as [email protected], as text, as text and as [email protected]; the last three are where the import differs from GitHub, and the test comments say why:

$ for t in 'https\://x.com' 'see .www.x.com' 'https\://x.com/[email protected]' 'www._x.com. next' 'www.café_bar.com' 'a\@www.x.com\@b.co'; do printf '%s\n' "$t" | cmark-gfm -e autolink; done
<p>https://x.com</p>
<p>see .www.x.com</p>
<p>https://x.com/<a href="mailto:[email protected]">[email protected]</a></p>
<p><a href="http://www._x.com">www._x.com</a>. next</p>
<p><a href="http://www.caf%C3%A9_bar.com">www.café_bar.com</a></p>
<p>a@<a href="mailto:[email protected]">[email protected]</a></p>

Before

$ pnpm vitest run --project unit packages/lexical-mdast/src/__tests__/unit/MdastAutolinkLiteral.test.ts   # on main, without the tests of the internal transform
     × reads back the export of "https://x.com" as text
     × reads back the export of "www.x.com" as text
     × imports "https\\://x.com"
     × imports "&#x77;ww.x.com"
 Test Files  1 failed (1)
      Tests  48 failed | 20 passed (68)

After

$ pnpm vitest run --project unit packages/lexical-mdast
      Tests  1077 passed (1077)
$ pnpm run test-unit
 Test Files  1039 passed | 6 skipped (1045)
      Tests  41033 passed | 423 expected fail | 174 skipped (41630)

…mport as GitHub comments do

## Description

The export writes a URL typed as text with an escape, so that GitHub shows it as text: `https://x.com` exports as `https\://x.com` and `www.x.com` as `www\.x.com`. The import links both again, because the transform of `mdast-util-gfm-autolink-literal` finds URL literals in the decoded text, where the escape is gone. GitHub renders comments (`POST /markdown` with `mode: gfm`) with URL literals found only in the Markdown as written and email literals also in the decoded text: `https\://x.com` shows as text there and `a\@b.co` as a link. The library follows the file mode instead, where `https\://x.com` links too, so with it a URL typed as text cannot read back as text.

This updates `mdast-util-gfm-autolink-literal` from `^2.0.1` to `^2.1.2` and reads literal autolinks as GitHub comments do: a `www.` or `http(s)://` URL links only where micromark finds it in the source, and an email, `mailto:` or `xmpp:` literal links where the library's transform finds it. Before that transform runs, the import puts `q` in place of the first letter of each `www.` or `http(s)://` in the text, so that the transform starts no URL there but reads emails as before, and then puts the letters back. Typed `https://x.com` and `www.x.com` now read back as text.

Markdown written elsewhere imports differently where GitHub comments read it differently from the transform: a `www.` URL right after `.`, `!`, `"` or a code span (`see .www.x.com`, `` `code`www.a.example ``) or one written with a character reference (`&#x77;ww.x.com`) now imports as text, as GitHub shows it, and an email inside an escaped URL (`https\://x.com/[email protected]`) now links on its own instead of the whole URL. A URL that GitHub links but micromark does not find in the source now imports as text too: `www._x.com. next`, where GitHub links `www._x.com` because cmark-gfm checks the `_` of the domain before trimming the `.`, and `www.café_bar.com`. Plain URLs and emails import as before. Everything in `@lexical/mdast` is experimental, and 2.1.2 already changes some imports on its own (CJK before an email, `mailto:`, a domain that starts with punctuation), but this is still a change for documents written elsewhere, so the changeset lists it.

2.1.2 ships the rule that escapes the `.` of `www.` before any character, which meta#9956 added here, so that rule is removed. 2.1.2 also escapes `:` after an uppercase `P` or `S`, so Markdown `FTP://a.co/ ©_a_` now exports as `FTP\://a.co/ &#xA9;_a_`, which cmark-gfm reads as the text and italic that Lexical has, where before it read one link. Two literals after a code span both export in resource form now (`` `x`[www.a.example](http://www.a.example) and [www.b.example](http://www.b.example) ``): the first no longer reads back as a link, and the export from meta#9970 writes every literal from the first one that would read back differently in that form.

Most of the new tests pin an input against what cmark-gfm 0.29.0.gfm.14 links, since each was a case where a simpler version of this change read differently from GitHub. A few replace the library's transform with one that returns pieces that do not line up, to check that the import then keeps the text as it was rather than leave a `q` in it.

## Test plan

Compared by the link texts against cmark-gfm 0.29.0.gfm.14 (`-e autolink -e tasklist`), which agrees with GitHub comments for these inputs, the import with this change and with 2.1.2 alone:

- 3 × 30,000 random paragraphs of letters, CJK, punctuation, escapes, references, `www`, `https://`, `mailto:` and `@`: 29,732 / 29,713 / 29,711 agree with 2.1.2 alone, 29,914 / 29,904 / 29,901 with this change; 2 that agreed no longer do.
- 6,000 strict and 5,000 CJK-friendly (with `MdastHtmlExtension`) paragraphs built around escaped URLs and emails in emphasis, links, task lists, headings, quotes and tables: 1,925 and 1,583 agree with 2.1.2 alone, 5,059 and 4,210 with this change; the 12 and 12 that only 2.1.2 got right are emails such as `a\@www.x.com\@b.co`, where the library's email pattern differs from cmark-gfm.
- 3,900 typed texts exported and imported again: no URL reads back as a link (1,120 with 2.1.2 alone).

### Before

```
$ pnpm vitest run --project unit packages/lexical-mdast/src/__tests__/unit/MdastAutolinkLiteral.test.ts   # on main, without the tests of the internal transform
     × reads back the export of "https://x.com" as text
     × reads back the export of "www.x.com" as text
     × imports "https\\://x.com"
     × imports "&#x77;ww.x.com"
 Test Files  1 failed (1)
      Tests  48 failed | 20 passed (68)
```

### After

```
$ pnpm vitest run --project unit packages/lexical-mdast
      Tests  1075 passed (1075)
$ pnpm run test-unit
 Test Files  1039 passed | 6 skipped (1045)
      Tests  41031 passed | 423 expected fail | 174 skipped (41628)
```
@vercel

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

rootnode-bot Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

AI review status for this pull request.

Review status Updated
🟢 Reviewed (for maintainers only) Nov 28, 2026, 3:16 PM UTC

@pkg-pr-new

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

Copy link
Copy Markdown
lexical

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

@lexical/a11y

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

@lexical/clipboard

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

@lexical/code

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

@lexical/code-core

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

@lexical/code-prism

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

@lexical/code-shiki

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

@lexical/compiler

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

@lexical/devtools-core

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

@lexical/dragon

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

@lexical/eslint-plugin

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

@lexical/extension

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

@lexical/fast-check

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

@lexical/file

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

@lexical/hashtag

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

@lexical/headless

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

@lexical/history

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

@lexical/html

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

@lexical/internal

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

@lexical/link

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

@lexical/list

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

@lexical/mark

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

@lexical/markdown

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

@lexical/mdast

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

@lexical/offset

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

@lexical/overflow

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

@lexical/plain-text

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

@lexical/react

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

@lexical/rich-text

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

@lexical/selection

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

@lexical/table

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

@lexical/tailwind

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

@lexical/text

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

@lexical/utils

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

@lexical/y

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

@lexical/yjs

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

commit: e0e4ccd

…e by the ratio of two sizes

## Description

The test that a long text is masked in linear time imported 100,000 URL starts and asserted that it took less than 4,000 ms. It took 359 to 615 ms locally but 8,460 ms on CI, where most of the time is the parse. It now runs the transforms alone on a text of 20,000 and of 80,000 URL starts and asserts that the larger takes less than eight times as long, taking the fastest of five runs of each; a mask that searched the text again from its start for each URL takes about twenty times as long.

## Test plan

### Before

```
FAIL  packages/lexical-mdast/src/__tests__/unit/MdastAutolinkLiteral.test.ts > MdastAutolinkLiteralExtension > masks the URLs of a long text in linear time
AssertionError: expected 8460.325905000034 to be less than 4000
```

### After

```
$ pnpm vitest run --project unit packages/lexical-mdast
      Tests  1075 passed (1075)
```

With the mask replaced by a loop that searches again from the start after each URL:

```
AssertionError: expected 20.052862472209252 to be less than 8
```

@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. Finding URL literals in the Markdown as written, and emails in the decoded text, follows the GFM spec's own wording (§6.9). Extended autolinks "can only come at the beginning of a line, after whitespace, or any of the delimiting characters *, _, ~, and (", while an email "will be recognised when an email address is recognised within any text node". The two cases where the import now differs from GitHub (www._x.com., www.café_bar.com) are also what the spec asks for, since "no underscores may be present in the last two segments of the domain". The masking transform lines up exactly with the URL pattern of [email protected], and typed URLs now round-trip as text in both punctuation modes.

A few optional, non-blocking suggestions:

  1. Verify: could mention two export changes (.changeset/mdast-gfm-autolink-literal-2-1-2.md, line 7).

    • 2.0.1 also escaped a . after a single w when a letter, digit, -, . or _ followed. So text like new.file used to export as new\.file, and with 2.1.2's [Ww]{3} rule it exports bare.
    • After a code span, later bare literals in the same paragraph now export as [text](url) (MdastImportExport.test.ts, the "the next literal too" case).

    Both read back unchanged. AGENTS.md asks a fix that changes observable output to say what to test in Verify:, so one sentence would cover it.

  2. The mask copies the library's URL pattern (packages/lexical-mdast/src/autolinkLiteral.ts, line 16). The lockfile pins 2.1.2, but ^2.1.2 lets installs downstream resolve a later 2.x. If that version's URL pattern grows, those URLs would quietly link from the decoded text again. The restore keeps the text intact, so nothing breaks. Pinning ~2.1.2, or a test that the library transform finds no URL in masked text, would surface that on a bump.

  3. The cmark-gfm comparison in the Test plan is described rather than reproducible, and the expected values in MdastAutolinkLiteral.test.ts come from those runs. AGENTS.md asks the Test plan for real pasted output. Committing the generator, or pasting a few of the inputs that still differ, would let others rerun it.

Automated review (maintainer link)

…est that the mask leaves no URL

## Description

The changeset said the export rule for the `.` of `www.` now comes from the library "with the same output", but 2.0.1 also escaped a `.` after a single `w` before a letter, digit, `-`, `.` or `_`: text `new.file` exported as `new\.file` and now exports as `new.file`. It also did not say that after a code span a bare literal that follows the first one now exports as `[text](url)`. `Verify:` now says both, and the export round-trip table has a `new.file` row.

The mask copies the start of the URL pattern of `mdast-util-gfm-autolink-literal` 2.1.2, which `^2.1.2` lets a later 2.x widen. A new test runs the transforms on a text with `http://`, `HTTPS://`, `Http://`, `www.`, `WWW.`, `Www.`, `ftp://`, `FTP://`, `file://` and an email and expects only the email to link.

## Test plan

### Before

With the mask reduced to `www.` (`const URL_START = /www(?=\.)/gi;`):

```
$ pnpm vitest run --project unit packages/lexical-mdast/src/__tests__/unit/MdastAutolinkLiteral.test.ts -t "masked text"
      Tests  1 failed | 77 skipped (78)
```

### After

```
$ pnpm vitest run --project unit packages/lexical-mdast
      Tests  1077 passed (1077)
$ pnpm run test-unit
 Test Files  1039 passed | 6 skipped (1045)
      Tests  41033 passed | 423 expected fail | 174 skipped (41630)
```
@mayrang

mayrang commented Nov 28, 2026

Copy link
Copy Markdown
Collaborator Author

Pasted the cmark-gfm output for the pinned cases into the Test plan, the three that differ from GitHub included. The random comparisons came from scratch scripts I didn't add to the 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.

This looks good to me. Reading URL literals only from the Markdown as written, while emails still come from the decoded text, matches how the GFM spec words the two rules: §6.9 recognises URL autolinks by their position in the source and email autolinks "within any text node". It also fixes the round trip where text like https://x.com was exported as https\://x.com and came back as a link. The new tests cover both punctuation modes, the surrounding syntax (task items, emphasis, headings, tables, links, raw HTML) and the restore's failure paths.

Thanks for adding the new.file and post-code-span export changes to the changeset's Verify: paragraph. Thanks too for the test that runs the real library over a masked sample (MdastAutolinkLiteral.test.ts:352): if a later version of mdast-util-gfm-autolink-literal widens its URL pattern, CI will now catch it.

One optional, non-blocking suggestion:

  • packages/lexical-mdast/src/__tests__/unit/MdastAutolinkLiteral.test.ts:132: the comment says the expected values in the imports %j table are what cmark-gfm reads, but the comparison that chose them ran outside the PR. A short note with the cmark-gfm version and flags (0.29.0.gfm.14, -e autolink), or a small fixture of the inputs you compared, would let the next change to this transform re-check them.

Automated review (maintainer link)

…the expected autolink literals

## Description

The comment above the `imports %j` table in `MdastAutolinkLiteral.test.ts` said its expected values are what cmark-gfm reads, without the version or how to check one. It now names cmark-gfm 0.29.0.gfm.14 and the command (`printf '%s\n' '<markdown>' | cmark-gfm -e autolink`). Comment only.

## Test plan

### After

```
$ pnpm vitest run --project unit packages/lexical-mdast/src/__tests__/unit/MdastAutolinkLiteral.test.ts
      Tests  78 passed (78)
```

@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. URL literals are now read only from the Markdown as written, while emails still come from the decoded text. That matches how the GFM spec words the two rules: §6.9 places extended www. and http(s):// autolinks by their position in the source, and recognises email autolinks "within any text node". It also fixes the round trip where text like https://x.com was exported as https\://x.com and came back as a link. Thanks for naming the cmark-gfm version and command beside the pinned cases (MdastAutolinkLiteral.test.ts:130-132), and for the test that runs the real library over a masked sample, which will catch a future version that widens its URL pattern.

One optional, non-blocking suggestion:

  • .changeset/mdast-gfm-autolink-literal-2-1-2.md:7: AGENTS.md (Changesets) and .changeset/README.md ("Behavior changes") ask a fix that changes output to say what to verify. The Verify: paragraph mentions the uppercase-scheme escape only for FTP:// under strict-commonmark. 2.1.2 escapes : after an uppercase P or S in both modes, so text HTTPS://x.com now exports as HTTPS\://x.com (pinned at MdastAutolinkLiteral.test.ts:102); before, it was written bare and read back as a link. One sentence saying so would let people who compare exported Markdown expect the new output.

Automated review (maintainer link)

…w export with an escape

## Description

2.1.2 escapes `:` after an uppercase `P` or `S` in both punctuation modes, so text `HTTPS://x.com`, which exported bare and read back as a link, now exports as `HTTPS\://x.com` and reads back as text. The changeset's `Verify:` paragraph only mentioned this for `FTP://` under `strict-commonmark`; it now says it for `HTTPS://x.com`, which `MdastAutolinkLiteral.test.ts` pins. Changeset only.

@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 thorough follow-ups.

URL literals (www., http(s)://) now come only from what micromark finds in the source, while emails still come from the decoded text. That matches how GFM §6.9 separates the two: a www autolink is recognised when the text www. "is found followed by a valid domain", an email autolink "when an email address is recognised within any text node". It also matches how GitHub renders comments.

With this change, a URL typed as text survives an export and import as text in both punctuation modes (MdastAutolinkLiteral.test.ts:109-128). When the pieces do not line up, the restore in packages/lexical-mdast/src/autolinkLiteral.ts falls back to the original children (:154-155), so the stand-in q cannot leak into a document.

The earlier suggestions are all addressed at this head:

  • The changeset's Verify: paragraph now covers new.file, the resource form after a code span and HTTPS\://x.com.
  • MdastAutolinkLiteral.test.ts:353-377 will fail if a later 2.x release widens the library's URL pattern beyond what the mask covers.

I have no further suggestions.

Automated review (maintainer link)

@etrepum
etrepum added this pull request to the merge queue Nov 28, 2026
Merged via the queue into meta:main with commit 0e6fc89 Nov 28, 2026
61 checks passed

This branch was successfully deployed

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