Skip to content

[lexical-mdast] Bug Fix: Emphasis typed inside a word of any script stays as typed - #9999

Merged
potatowagon merged 4 commits into
meta:mainfrom
vjeux:mdast-word-characters-any-script
Dec 4, 2026
Merged

potatowagon merged 4 commits into
meta:mainfrom
vjeux:mdast-word-characters-any-script

Conversation

@vjeux

@vjeux vjeux commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Description

Since #9920, typing x*y* keeps it as typed, because a * or ~ run inside a word is more often math or a name. But only ASCII letters and digits counted as inside a word, so café*x*, слово*курсив* and λέξη*πλάγια* still converted mid-word.

A letter or decimal digit of any script now counts, with any combining marks after it, so café*x* stays as typed, and so does cafe\u0301*x*, an e with a combining acute (U+0301). The exceptions, where there is no word boundary to wait for, are unchanged: the CJK of the CJK-friendly amendment (isCjkCharacter, which also covers Hangul), and the scripts Unicode breaks into words by dictionary (Line_Break=SA): Thai, Lao, Khmer, Myanmar, Tai Le, New Tai Lue, Tai Tham, Tai Viet and Ahom. There, emphasis still converts after a letter (日本*語*, ภาษาไทย*เอียง*). A symbol is not inside a word: a character an emoji presentation selector (U+FE0F) or a keycap (an enclosing mark) follows, or an ideograph with an ideographic variation selector, so ❤️*x*, 1️⃣*x* and 葛󠄀*強調* still convert. Markdown import and export are untouched.

This supersedes the two earlier descriptions on the PR. Two later commits take the automated review's remaining points:

  • A number that is not a decimal digit, such as ① or ½, is not a word character ([\p{L}\p{Nd}], the any-script form of [A-Za-z0-9], rather than [\p{L}\p{N}]). ① is not in isCjkCharacter, so 手順①*注意* converted after the second commit where main converts it; it converts again.
  • The scripts written without spaces are matched by their script (\p{sc=…}) rather than their script extensions (\p{scx=…}), which also take in letters other scripts share, such as U+02BC, the apostrophe Ukrainian writes inside a word. So обʼ*єкт* now stays as typed, as after any other letter.

Changeset

.changeset/mdast-typed-emphasis-any-script.md (@lexical/mdast patch, [fix], with a Verify: paragraph).

Test plan

Before

MdastStream.ts as on main (4aa11ac), with this branch's tests:

./node_modules/.bin/vitest --project unit --no-watch -t "closing delimiter after|still applies emphasis" packages/lexical-mdast/src/__tests__/unit/MdastShortcuts.test.ts

7 of the 34 selected cases fail: café*x*, слово*курсив*, λέξη*πλάγια*, café**x**, café~~x~~, cafe\u0301*x* (U+0301) and обʼ*єкт* (U+02BC). The symbol, CJK, Line_Break=SA, ① and ½ cases pass on main and guard against regressions.

 Test Files  1 failed (1)
      Tests  7 failed | 27 passed | 64 skipped (98)

After

The same command on this branch:

 Test Files  1 passed (1)
      Tests  34 passed | 64 skipped (98)

The full unit suite (pnpm run test-unit, run at two workers):

 Test Files  1041 passed | 6 skipped (1047)
      Tests  41131 passed | 423 expected fail | 174 skipped (41728)

pnpm run ci-check exits 0 (TypeScript, Flow Found 0 errors, Prettier, ESLint, and the changeset check all pass). The branch is merged up to date with main (c302b4b); main's #10001 fixes the playground DateTimeComponent date-picker tests that fail in December, which were the only failures in the core-tests / unit (24.x) run.

Not run: the browser-mode tests (pnpm run test-browser) and the e2e suites. The change is in the shortcut scanner, which the unit tests above drive by typing into an editor.

🤖 Generated with Claude Code

…tays as typed

## Description

Since meta#9920, typing `x*y*` keeps it as typed, because a `*` or `~` run inside a word is more often math or a name. But only ASCII letters and digits count as inside a word, so `café*x*`, `слово*курсив*` and `λέξη*πλάγια*` still convert mid-word.

A letter, digit or mark of any script now counts, so `café*x*` stays as typed, and so does `cafe\u0301*x*`, an `e` with a combining acute (U+0301). The exceptions are scripts written without spaces between words: the CJK of the CJK-friendly amendment (`isCjkCharacter`, which also covers Hangul, as before), Thai, Lao, Khmer and Myanmar. There, emphasis still converts after a letter: `日本*語*`, `カタカナー*強調*`, `ภาษาไทย*เอียง*`.

## Changeset

`.changeset/mdast-typed-emphasis-any-script.md` ([fix], with `Verify:`).

## Test plan

### Before

`MdastStream.ts` as on main (4aa11ac), with this branch's tests:

```
./node_modules/.bin/vitest --project unit --no-watch --reporter=verbose --silent=true -t "closing delimiter after|still applies emphasis" packages/lexical-mdast/src/__tests__/unit/MdastShortcuts.test.ts
```

The lines of the selected tests and the summary (the 64 skipped tests and the assertion messages are left out):

```
 ✓ |unit| packages/lexical-mdast/src/__tests__/unit/MdastShortcuts.test.ts > @lexical/mdast streaming shortcuts > inline shortcuts (on closing delimiter) > a closing delimiter after a mid-word opener leaves 2*3* as text 29ms
 ✓ |unit| packages/lexical-mdast/src/__tests__/unit/MdastShortcuts.test.ts > @lexical/mdast streaming shortcuts > inline shortcuts (on closing delimiter) > a closing delimiter after a mid-word opener leaves x*y* as text 4ms
 ✓ |unit| packages/lexical-mdast/src/__tests__/unit/MdastShortcuts.test.ts > @lexical/mdast streaming shortcuts > inline shortcuts (on closing delimiter) > a closing delimiter after a mid-word opener leaves mid*word* as text 4ms
 ✓ |unit| packages/lexical-mdast/src/__tests__/unit/MdastShortcuts.test.ts > @lexical/mdast streaming shortcuts > inline shortcuts (on closing delimiter) > a closing delimiter after a mid-word opener leaves foo**bar** as text 3ms
 ✓ |unit| packages/lexical-mdast/src/__tests__/unit/MdastShortcuts.test.ts > @lexical/mdast streaming shortcuts > inline shortcuts (on closing delimiter) > a closing delimiter after a mid-word opener leaves x~~y~~ as text 3ms
 × |unit| packages/lexical-mdast/src/__tests__/unit/MdastShortcuts.test.ts > @lexical/mdast streaming shortcuts > inline shortcuts (on closing delimiter) > a closing delimiter after a mid-word opener leaves café*x* as text 13ms
 × |unit| packages/lexical-mdast/src/__tests__/unit/MdastShortcuts.test.ts > @lexical/mdast streaming shortcuts > inline shortcuts (on closing delimiter) > a closing delimiter after a mid-word opener leaves слово*курсив* as text 4ms
 × |unit| packages/lexical-mdast/src/__tests__/unit/MdastShortcuts.test.ts > @lexical/mdast streaming shortcuts > inline shortcuts (on closing delimiter) > a closing delimiter after a mid-word opener leaves λέξη*πλάγια* as text 3ms
 × |unit| packages/lexical-mdast/src/__tests__/unit/MdastShortcuts.test.ts > @lexical/mdast streaming shortcuts > inline shortcuts (on closing delimiter) > a closing delimiter after a mid-word opener leaves café**x** as text 4ms
 × |unit| packages/lexical-mdast/src/__tests__/unit/MdastShortcuts.test.ts > @lexical/mdast streaming shortcuts > inline shortcuts (on closing delimiter) > a closing delimiter after a mid-word opener leaves café~~x~~ as text 4ms
 × |unit| packages/lexical-mdast/src/__tests__/unit/MdastShortcuts.test.ts > @lexical/mdast streaming shortcuts > inline shortcuts (on closing delimiter) > a closing delimiter after a combining mark (U+0301) leaves cafe\u0301*x* as text 3ms
 ✓ |unit| packages/lexical-mdast/src/__tests__/unit/MdastShortcuts.test.ts > @lexical/mdast streaming shortcuts > inline shortcuts (on closing delimiter) > still applies emphasis after a space, punctuation or text written without spaces: a *b* 3ms
 ✓ |unit| packages/lexical-mdast/src/__tests__/unit/MdastShortcuts.test.ts > @lexical/mdast streaming shortcuts > inline shortcuts (on closing delimiter) > still applies emphasis after a space, punctuation or text written without spaces: (*b* 3ms
 ✓ |unit| packages/lexical-mdast/src/__tests__/unit/MdastShortcuts.test.ts > @lexical/mdast streaming shortcuts > inline shortcuts (on closing delimiter) > still applies emphasis after a space, punctuation or text written without spaces: café *x* 3ms
 ✓ |unit| packages/lexical-mdast/src/__tests__/unit/MdastShortcuts.test.ts > @lexical/mdast streaming shortcuts > inline shortcuts (on closing delimiter) > still applies emphasis after a space, punctuation or text written without spaces: 中文*强调* 3ms
 ✓ |unit| packages/lexical-mdast/src/__tests__/unit/MdastShortcuts.test.ts > @lexical/mdast streaming shortcuts > inline shortcuts (on closing delimiter) > still applies emphasis after a space, punctuation or text written without spaces: 日本*語* 2ms
 ✓ |unit| packages/lexical-mdast/src/__tests__/unit/MdastShortcuts.test.ts > @lexical/mdast streaming shortcuts > inline shortcuts (on closing delimiter) > still applies emphasis after a space, punctuation or text written without spaces: カタカナー*強調* 2ms
 ✓ |unit| packages/lexical-mdast/src/__tests__/unit/MdastShortcuts.test.ts > @lexical/mdast streaming shortcuts > inline shortcuts (on closing delimiter) > still applies emphasis after a space, punctuation or text written without spaces: 단어*기울임* 2ms
 ✓ |unit| packages/lexical-mdast/src/__tests__/unit/MdastShortcuts.test.ts > @lexical/mdast streaming shortcuts > inline shortcuts (on closing delimiter) > still applies emphasis after a space, punctuation or text written without spaces: ภาษาไทย*เอียง* 2ms

 Test Files  1 failed (1)
      Tests  6 failed | 13 passed | 64 skipped (83)
```

### After

The same command on this branch:

```
 ✓ |unit| packages/lexical-mdast/src/__tests__/unit/MdastShortcuts.test.ts > @lexical/mdast streaming shortcuts > inline shortcuts (on closing delimiter) > a closing delimiter after a mid-word opener leaves 2*3* as text 31ms
 ✓ |unit| packages/lexical-mdast/src/__tests__/unit/MdastShortcuts.test.ts > @lexical/mdast streaming shortcuts > inline shortcuts (on closing delimiter) > a closing delimiter after a mid-word opener leaves x*y* as text 4ms
 ✓ |unit| packages/lexical-mdast/src/__tests__/unit/MdastShortcuts.test.ts > @lexical/mdast streaming shortcuts > inline shortcuts (on closing delimiter) > a closing delimiter after a mid-word opener leaves mid*word* as text 4ms
 ✓ |unit| packages/lexical-mdast/src/__tests__/unit/MdastShortcuts.test.ts > @lexical/mdast streaming shortcuts > inline shortcuts (on closing delimiter) > a closing delimiter after a mid-word opener leaves foo**bar** as text 3ms
 ✓ |unit| packages/lexical-mdast/src/__tests__/unit/MdastShortcuts.test.ts > @lexical/mdast streaming shortcuts > inline shortcuts (on closing delimiter) > a closing delimiter after a mid-word opener leaves x~~y~~ as text 3ms
 ✓ |unit| packages/lexical-mdast/src/__tests__/unit/MdastShortcuts.test.ts > @lexical/mdast streaming shortcuts > inline shortcuts (on closing delimiter) > a closing delimiter after a mid-word opener leaves café*x* as text 3ms
 ✓ |unit| packages/lexical-mdast/src/__tests__/unit/MdastShortcuts.test.ts > @lexical/mdast streaming shortcuts > inline shortcuts (on closing delimiter) > a closing delimiter after a mid-word opener leaves слово*курсив* as text 4ms
 ✓ |unit| packages/lexical-mdast/src/__tests__/unit/MdastShortcuts.test.ts > @lexical/mdast streaming shortcuts > inline shortcuts (on closing delimiter) > a closing delimiter after a mid-word opener leaves λέξη*πλάγια* as text 3ms
 ✓ |unit| packages/lexical-mdast/src/__tests__/unit/MdastShortcuts.test.ts > @lexical/mdast streaming shortcuts > inline shortcuts (on closing delimiter) > a closing delimiter after a mid-word opener leaves café**x** as text 3ms
 ✓ |unit| packages/lexical-mdast/src/__tests__/unit/MdastShortcuts.test.ts > @lexical/mdast streaming shortcuts > inline shortcuts (on closing delimiter) > a closing delimiter after a mid-word opener leaves café~~x~~ as text 3ms
 ✓ |unit| packages/lexical-mdast/src/__tests__/unit/MdastShortcuts.test.ts > @lexical/mdast streaming shortcuts > inline shortcuts (on closing delimiter) > a closing delimiter after a combining mark (U+0301) leaves cafe\u0301*x* as text 3ms
 ✓ |unit| packages/lexical-mdast/src/__tests__/unit/MdastShortcuts.test.ts > @lexical/mdast streaming shortcuts > inline shortcuts (on closing delimiter) > still applies emphasis after a space, punctuation or text written without spaces: a *b* 4ms
 ✓ |unit| packages/lexical-mdast/src/__tests__/unit/MdastShortcuts.test.ts > @lexical/mdast streaming shortcuts > inline shortcuts (on closing delimiter) > still applies emphasis after a space, punctuation or text written without spaces: (*b* 3ms
 ✓ |unit| packages/lexical-mdast/src/__tests__/unit/MdastShortcuts.test.ts > @lexical/mdast streaming shortcuts > inline shortcuts (on closing delimiter) > still applies emphasis after a space, punctuation or text written without spaces: café *x* 3ms
 ✓ |unit| packages/lexical-mdast/src/__tests__/unit/MdastShortcuts.test.ts > @lexical/mdast streaming shortcuts > inline shortcuts (on closing delimiter) > still applies emphasis after a space, punctuation or text written without spaces: 中文*强调* 3ms
 ✓ |unit| packages/lexical-mdast/src/__tests__/unit/MdastShortcuts.test.ts > @lexical/mdast streaming shortcuts > inline shortcuts (on closing delimiter) > still applies emphasis after a space, punctuation or text written without spaces: 日本*語* 3ms
 ✓ |unit| packages/lexical-mdast/src/__tests__/unit/MdastShortcuts.test.ts > @lexical/mdast streaming shortcuts > inline shortcuts (on closing delimiter) > still applies emphasis after a space, punctuation or text written without spaces: カタカナー*強調* 3ms
 ✓ |unit| packages/lexical-mdast/src/__tests__/unit/MdastShortcuts.test.ts > @lexical/mdast streaming shortcuts > inline shortcuts (on closing delimiter) > still applies emphasis after a space, punctuation or text written without spaces: 단어*기울임* 3ms
 ✓ |unit| packages/lexical-mdast/src/__tests__/unit/MdastShortcuts.test.ts > @lexical/mdast streaming shortcuts > inline shortcuts (on closing delimiter) > still applies emphasis after a space, punctuation or text written without spaces: ภาษาไทย*เอียง* 5ms

 Test Files  1 passed (1)
      Tests  19 passed | 64 skipped (83)
```

The projects of `pnpm run test-unit`, run as `./node_modules/.bin/vitest --project unit --project unit-size --project scripts-unit --no-watch --maxWorkers=8 --reporter=dot --silent=passed-only`:

```
 Test Files  1039 passed | 6 skipped (1045)
      Tests  41044 passed | 423 expected fail | 174 skipped (41641)
```

`pnpm run ci-check` exits 0. Flow prints `Found 0 errors`, and the changeset check `Changeset check passed: 208 pending changeset(s) valid.`

Not run: the browser-mode tests (`pnpm run test-browser`) and the e2e suites. The change is in the shortcut scanner, which the unit tests above drive by typing into an editor.

Drafted with an AI coding agent; the tests were run as described.
@vercel

vercel Bot commented Nov 30, 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 Dec 4, 2026 3:52am UTC
lexical-playground Ready Ready Preview Dec 4, 2026 3:52am 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 30, 2026
@rootnode-bot

rootnode-bot Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

AI review status for this pull request.

Review status Updated
🟢 Reviewed (for maintainers only) Dec 4, 2026, 4:06 AM UTC

@pkg-pr-new

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

Copy link
Copy Markdown
lexical

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

@lexical/a11y

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

@lexical/clipboard

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

@lexical/code

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

@lexical/code-core

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

@lexical/code-prism

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

@lexical/code-shiki

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

@lexical/compiler

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

@lexical/devtools-core

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

@lexical/dragon

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

@lexical/eslint-plugin

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

@lexical/extension

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

@lexical/fast-check

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

@lexical/file

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

@lexical/hashtag

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

@lexical/headless

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

@lexical/history

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

@lexical/html

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

@lexical/internal

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

@lexical/link

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

@lexical/list

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

@lexical/mark

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

@lexical/markdown

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

@lexical/mdast

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

@lexical/offset

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

@lexical/overflow

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

@lexical/plain-text

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

@lexical/react

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

@lexical/rich-text

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

@lexical/selection

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

@lexical/table

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

@lexical/tailwind

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

@lexical/text

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

@lexical/utils

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

@lexical/y

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

@lexical/yjs

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

commit: 4aed902

@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, thanks. The rule reads well: a letter, digit or mark of a space-separated script now holds the typed shortcut back, the CJK-friendly set plus Thai, Lao, Khmer and Myanmar still convert, and import and export are untouched. The new cases fail against the old ASCII-only check and pass at this head. A few optional, non-blocking suggestions:

  1. Variation selectors and enclosing marks (packages/lexical-mdast/src/MdastStream.ts:63). \p{M} also matches U+FE0F, the ideographic variation selectors (U+E0100–U+E01EF) and the keycap U+20E3, and followsWordCharacter classifies only the code point before the opener. So ❤️*x* (U+2764 U+FE0F, the usual emoji form) now stays as typed while ❤*x* converts, and 葛󠄀*強調* (an ideograph with an IVS) stays as typed while 葛*強調* converts; both converted before. The package's CJK-friendly import already reads a selector as part of the character it varies (readBefore in packages/lexical-mdast/src/cjkFriendly.ts, and the IVS class at lines 35–36). Stepping back over marks to their base character before classifying it keeps cafe\u0301*x* and the Thai, Lao, Khmer and Myanmar cases as they are, and restores the emoji and IVS rows:

    const MARK = /\p{M}/u;
    const WORD_CHARACTER = /[\p{L}\p{N}]/u;
    
    function followsWordCharacter(value: string, offset: number): boolean {
      for (let end = offset; end > 0; ) {
        const code = value.charCodeAt(end - 1);
        const start =
          code >= 0xdc00 && code <= 0xdfff && end > 1 ? end - 2 : end - 1;
        const character = value.slice(start, end);
        if (!MARK.test(character)) {
          return (
            WORD_CHARACTER.test(character) &&
            !isCjkCharacter(character) &&
            !UNSPACED_SCRIPT.test(character)
          );
        }
        end = start;
      }
      return false;
    }

    Adding ❤️*x* and 葛󠄀*強調* to the "still applies emphasis" cases would pin it.

  2. Cases for the other scripts written without spaces (packages/lexical-mdast/src/__tests__/unit/MdastShortcuts.test.ts, the "still applies emphasis" list). UNSPACED_SCRIPT names Lao, Khmer and Myanmar, but only Thai has a case, and that Thai word ends in a consonant. A Lao, a Khmer and a Myanmar case, plus a Thai word ending in a tone mark such as ที่*เน้น*, would pin the script classes the change relies on.

  3. Nit: other South-East Asian scripts written without spaces, such as Tai Tham, New Tai Lue, Tai Le and Tai Viet, now stay as typed after a letter. That is fine if the four main ones are the intended set; a word in the comment above UNSPACED_SCRIPT would say so.

In #9920 you deferred a docs sentence covering the typed exceptions. This change widens that rule, so that sentence can cover it too when it lands.

Automated review (maintainer link)

…nother Tai script still converts

## Description

A follow-up to the first commit, from the automated review. That commit counted any mark as part of a word and classified only the code point before the opener. So emphasis typed after an emoji with its presentation selector (`❤️*x*`), a keycap (`1️⃣*x*`) or an ideograph with an ideographic variation selector (`葛󠄀*強調*`) stayed as typed, though main converts all three.

The check now steps back over the marks to the character they belong to and classifies that one. An emoji presentation selector (U+FE0F) or an enclosing mark (a keycap) after it makes it a symbol. The scripts written without spaces are now all those Unicode breaks into words by dictionary (Line_Break=SA): Thai, Lao, Khmer, Myanmar, Tai Le, New Tai Lue, Tai Tham, Tai Viet and Ahom. New cases cover each of them, a Thai word that ends in a tone mark, and the three symbols.

## Test plan

### Before

The first commit's `MdastStream.ts`, with these tests:

```
./node_modules/.bin/vitest --project unit --no-watch --reporter=verbose --silent=true -t "closing delimiter after|still applies emphasis" packages/lexical-mdast/src/__tests__/unit/MdastShortcuts.test.ts
```

Summary (the run's lines are in the pull request's test plan):

```
 Test Files  1 failed (1)
      Tests  8 failed | 23 passed | 64 skipped (95)
```

The 8 that fail are the Tai Tham, New Tai Lue, Tai Le, Tai Viet and Ahom cases, `❤️*x*`, `1️⃣*x*` and `葛󠄀*強調*`.

### After

The same command on this commit:

```
 Test Files  1 passed (1)
      Tests  31 passed | 64 skipped (95)
```

Drafted with an AI coding agent; the tests were run as described.

@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. Treating a letter or number of any script, with its combining marks, as inside a word keeps café*x*, cafe\u0301*x* and слово*курсив* as typed. CJK, Hangul, the Line_Break=SA scripts, emoji, keycaps and an ideograph with a variation selector still convert. Reproduced locally: this branch's MdastShortcuts.test.ts run against main's MdastStream.ts fails the same six cases as your Before output, and all 95 tests pass on the branch.

A few optional, non-blocking suggestions:

  • packages/lexical-mdast/src/MdastStream.ts:64 (the same point as the earlier inline note): [\p{L}\p{N}] also counts numbers that are not digits, so ①, Ⅱ, ½ and ² now block the shortcut where main converts after them. CJK text is where this is most likely to be noticed. ①–⑳ have East Asian Width A, so isCjkCharacter does not cover them, and 手順①*注意* now stays as typed. /[\p{L}\p{Nd}]/u keeps those converting. If you prefer the current behaviour, which fits the math reading of x²*y*, add a case to the it.each tables to pin whichever you choose.
  • packages/lexical-mdast/src/MdastStream.ts:62-63 (nit): \p{scx=Thai} also matches U+02BC MODIFIER LETTER APOSTROPHE, whose Script_Extensions include Thai. So a * right after ʼ, which is a letter inside words such as Ukrainian обʼєкт, still converts. \p{sc=…} would match only the nine scripts' own letters and digits. The combining marks that carry those extensions are stepped over by the loop anyway. Behaviour here is the same as on main.
  • CI: the red core-tests / unit (24.x) job fails only in packages/lexical-playground/__tests__/unit/DateTimeComponent.test.tsx (expected a day to pick), which this change does not touch; MdastShortcuts.test.ts passes 95/95 in that run. main fixed those tests in #10001 by pinning the date the picker opens on, so updating the branch from main should turn the job green. A plain re-run is likely to fail the same way while it is still December.

Automated review (maintainer link)

vjeux added 2 commits December 3, 2026 17:45
… converts again

## Description

A follow-up to the second commit, from the automated review. The check counted every Unicode number as inside a word, so emphasis typed after a number that is not a decimal digit stayed as typed: `手順①*注意*` (`isCjkCharacter` does not cover ①) and `½*x*`. Main converts both.

It now counts letters and decimal digits (`[\p{L}\p{Nd}]`, the any-script form of `[A-Za-z0-9]`), so both convert again. The scripts written without spaces are now matched by their script (`\p{sc=…}`) instead of their script extensions, which also take in U+02BC, a letter Ukrainian writes inside words (`обʼєкт`). So `обʼ*єкт*` now stays as typed, as after any other letter; on main and after the second commit it converted.

## Changeset

`.changeset/mdast-typed-emphasis-any-script.md` now says "a letter or decimal digit", and its `Verify:` paragraph adds `½*x*`.

## Test plan

### Before

The second commit's `MdastStream.ts`, with these tests:

```
./node_modules/.bin/vitest --project unit --no-watch --reporter=verbose --silent=true -t "closing delimiter after|still applies emphasis" packages/lexical-mdast/src/__tests__/unit/MdastShortcuts.test.ts
```

The lines of the three new tests and the summary (the passing and skipped tests and the assertion messages are left out):

```
 × |unit| packages/lexical-mdast/src/__tests__/unit/MdastShortcuts.test.ts > @lexical/mdast streaming shortcuts > inline shortcuts (on closing delimiter) > a closing delimiter after a mid-word opener leaves обʼ*єкт* as text 18ms
 × |unit| packages/lexical-mdast/src/__tests__/unit/MdastShortcuts.test.ts > @lexical/mdast streaming shortcuts > inline shortcuts (on closing delimiter) > still applies emphasis after a space, punctuation, a symbol or text written without spaces: 手順①*注意* 4ms
 × |unit| packages/lexical-mdast/src/__tests__/unit/MdastShortcuts.test.ts > @lexical/mdast streaming shortcuts > inline shortcuts (on closing delimiter) > still applies emphasis after a space, punctuation, a symbol or text written without spaces: ½*x* 4ms

 Test Files  1 failed (1)
      Tests  3 failed | 31 passed | 64 skipped (98)
```

### After

The same command on this commit:

```
 ✓ |unit| packages/lexical-mdast/src/__tests__/unit/MdastShortcuts.test.ts > @lexical/mdast streaming shortcuts > inline shortcuts (on closing delimiter) > a closing delimiter after a mid-word opener leaves обʼ*єкт* as text 3ms
 ✓ |unit| packages/lexical-mdast/src/__tests__/unit/MdastShortcuts.test.ts > @lexical/mdast streaming shortcuts > inline shortcuts (on closing delimiter) > still applies emphasis after a space, punctuation, a symbol or text written without spaces: 手順①*注意* 5ms
 ✓ |unit| packages/lexical-mdast/src/__tests__/unit/MdastShortcuts.test.ts > @lexical/mdast streaming shortcuts > inline shortcuts (on closing delimiter) > still applies emphasis after a space, punctuation, a symbol or text written without spaces: ½*x* 4ms

 Test Files  1 passed (1)
      Tests  34 passed | 64 skipped (98)
```

Drafted with an AI coding agent; the tests were run as described.
## Description

Brings the branch up to date with main (c302b4b). Main's meta#10001 makes the playground's date picker tests pick a day that has a button, so its `DateTimeComponent.test.tsx` cases no longer fail in December; that file was the only failure in this branch's `core-tests / unit (24.x)` job. Main changed none of `MdastStream.ts`, `MdastShortcuts.test.ts` or `cjkFriendly.ts` since this branch's base (4aa11ac), and the merge has no conflicts.

## Test plan

### Before

The branch before the merge:

```
./node_modules/.bin/vitest --project unit --no-watch --reporter=verbose --silent=true packages/lexical-playground/__tests__/unit/DateTimeComponent.test.tsx
```

The lines of the failing tests and the summary (the assertion messages are left out):

```
 × |unit| packages/lexical-playground/__tests__/unit/DateTimeComponent.test.tsx > DateTimeComponent > (a) keeps a picked day all-day after checking the time box 310ms
 × |unit| packages/lexical-playground/__tests__/unit/DateTimeComponent.test.tsx > DateTimeComponent > (n) keeps a typed 00:00 when a day is picked 163ms
 × |unit| packages/lexical-playground/__tests__/unit/DateTimeComponent.test.tsx > DateTimeComponent > (p) keeps a timed chip at local midnight timed when a day is picked 118ms
 × |unit| packages/lexical-playground/__tests__/unit/DateTimeComponent.test.tsx > DateTimeComponent > (q) keeps a typed 00:00 when a day is picked after reopening 292ms
 × |unit| packages/lexical-playground/__tests__/unit/DateTimeComponent.test.tsx > DateTimeComponent > (d) keeps the stored time when the time field is empty 155ms
 × |unit| packages/lexical-playground/__tests__/unit/DateTimeComponent.test.tsx > DateTimeComponent > (e) gives a chip without a date an all-day date 147ms
 × |unit| packages/lexical-playground/__tests__/unit/DateTimeComponent.test.tsx > DateTimeComponent > (k) clears the time box and keeps the next day all-day 187ms
 × |unit| packages/lexical-playground/__tests__/unit/DateTimeComponent.test.tsx > DateTimeComponent with outside changes > (l) treats a redo of its own earlier change as an outside change 116ms

 Test Files  1 failed (1)
      Tests  8 failed | 12 passed (20)
```

### After

The same command after the merge:

```
 Test Files  1 passed (1)
      Tests  20 passed (20)
```

Drafted with an AI coding agent; the tests were run as described.

@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. Counting a letter or decimal digit of any script, with any combining marks after it, as inside a word closes the gap #9920 left for café*x*, слово*курсив* and cafe\u0301*x*. CJK, the Line_Break=SA scripts, an emoji followed by a presentation selector or a keycap, and numbers such as ① and ½ still convert. I ran the branch's MdastShortcuts.test.ts locally against the implementation on main: the 7 new mid-word cases fail there, and all 34 selected cases pass on this branch. The two earlier inline suggestions (variation selectors and keycaps, and \p{N} versus \p{Nd}) are addressed.

Two optional, non-blocking suggestions:

  1. Refresh the Test plan to the current head. The Before and After output in the description lists 31 tests and runs main at 4aa11ac91a47. The branch now has 34 matching cases, since the third commit added обʼ*єкт*, 手順①*注意* and ½*x*, and it now sits on a newer main. AGENTS.md (Commits and Pull Requests) asks the Test plan to carry the real Before and After output of the command that was run, and the third commit's message already has that output. The line "A letter or digit of any script now counts" could also say "decimal digit", to match WORD_CHARACTER (packages/lexical-mdast/src/MdastStream.ts:66) and the changeset.
  2. Javanese and Balinese now stay as typed. UNSPACED_SCRIPT (packages/lexical-mdast/src/MdastStream.ts:63-64) follows Line_Break=SA. Javanese (ꦗꦮ*x*) and Balinese (ᬩᬲ*x*) are also written without spaces between words, but they now stay as typed where main converts them (reproduced locally). If the rule should cover every script written without spaces, adding \p{sc=Javanese}\p{sc=Balinese} keeps them converting. If SA is the line you want, the comment above the regex could say so.

Automated review (maintainer link)

// (Line_Break=SA). Matched by script, not by script extension, which also
// takes in letters other scripts share, such as the apostrophe U+02BC.
const UNSPACED_SCRIPT =
/[\p{sc=Thai}\p{sc=Lao}\p{sc=Khmer}\p{sc=Myanmar}\p{sc=Tai_Le}\p{sc=New_Tai_Lue}\p{sc=Tai_Tham}\p{sc=Tai_Viet}\p{sc=Ahom}]/u;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Optional, non-blocking: this follows Line_Break=SA, so Javanese (ꦗꦮ*x*) and Balinese (ᬩᬲ*x*), which are also written without spaces between words, now stay as typed where main converts them (reproduced locally). If the rule should cover every script written without spaces, adding \p{sc=Javanese}\p{sc=Balinese} keeps them converting. If SA is the line you want, the comment above could say so.

@potatowagon
potatowagon added this pull request to the merge queue Dec 4, 2026
Merged via the queue into meta:main with commit f51d2f5 Dec 4, 2026
57 checks passed
@vjeux
vjeux deleted the mdast-word-characters-any-script branch December 4, 2026 22:10
vjeux added a commit to vjeux/lexical that referenced this pull request Dec 6, 2026
… inside another construct

## Description

Since meta#9921, `__init__` typed on its own stays as typed. Inside another construct the name still lost its underscores when the outer construct's closing delimiter was typed: `*the __init__*`, `~~old __init__~~`, `**__init__**` and `[see __init__](https://example.com)` each turned the name into a bold `init`.

When a construct converts, each name inside it (a `strong` from a `__` run around one word of ASCII letters, digits and underscores) now becomes the text that was typed, as the review of meta#9921 suggested. meta#9921's own top-level check is refactored into the shared `isTypedName` helper that this walk reuses. `__two words__` inside emphasis still converts to strong, and Markdown import is unchanged.

A `__` run flanked by `_` on both sides is left alone: `___word___` is `_`-emphasis around a `__`-strong (CommonMark §6.2), this package's underscore spelling of bold italic, not a name. Without the guard `___both___` would have typed as an italic `__both__` and `____init____` as a bold `__init__`; both still convert as before.

## Changeset

`.changeset/mdast-typed-names-inside-constructs.md` (`@lexical/mdast` patch, `[fix]`, with a `Verify:` paragraph).

## Test plan

### Before

`MdastStream.ts` from `main`, with this branch's new tests:

```
./node_modules/.bin/vitest --project unit --no-watch -t "a name inside|still converts" packages/lexical-mdast/src/__tests__/unit/MdastShortcuts.test.ts
```

The four "a name inside" cases fail (the name loses its underscores), and the two new "still converts" cases fail (the bold-italic runs lose theirs):

```
AssertionError: expected 'see init' to be 'see __init__'   (a name inside a link)
AssertionError: expected '__both__' to be 'both'           (___both___ still converts)
```

### After

The same command on this branch: the "a name inside" cases (text, format and `$convertToMarkdownString` round trip) and the "still converts" cases all pass.

```
 Test Files  1 passed (1)
      Tests  10 passed | 94 skipped (104)
```

The `@lexical/mdast` unit suite passes (`Test Files 21 passed (21)`, `Tests 1109 passed (1109)`), and so does the full unit suite (`pnpm run test-unit`). `pnpm run ci-check` exits 0 (TypeScript, Flow `Found 0 errors`, Prettier, ESLint and the changeset check). Rebased onto current `main` (which carries meta#9999).

Not run: the browser-mode tests and the e2e suites. The change is in the shortcut scanner, which the unit tests drive by typing into an editor.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

This branch was successfully deployed

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