Repository navigation
[lexical-mdast] Bug Fix: Emphasis typed inside a word of any script stays as typed - #9999
Conversation
…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.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
AI review status for this pull request.
|
lexical
@lexical/a11y
@lexical/clipboard
@lexical/code
@lexical/code-core
@lexical/code-prism
@lexical/code-shiki
@lexical/compiler
@lexical/devtools-core
@lexical/dragon
@lexical/eslint-plugin
@lexical/extension
@lexical/fast-check
@lexical/file
@lexical/hashtag
@lexical/headless
@lexical/history
@lexical/html
@lexical/internal
@lexical/link
@lexical/list
@lexical/mark
@lexical/markdown
@lexical/mdast
@lexical/offset
@lexical/overflow
@lexical/plain-text
@lexical/react
@lexical/rich-text
@lexical/selection
@lexical/table
@lexical/tailwind
@lexical/text
@lexical/utils
@lexical/y
@lexical/yjs
commit: |
There was a problem hiding this comment.
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:
-
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, andfollowsWordCharacterclassifies 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 (readBeforeinpackages/lexical-mdast/src/cjkFriendly.ts, and the IVS class at lines 35–36). Stepping back over marks to their base character before classifying it keepscafe\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. -
Cases for the other scripts written without spaces (
packages/lexical-mdast/src/__tests__/unit/MdastShortcuts.test.ts, the "still applies emphasis" list).UNSPACED_SCRIPTnames 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. -
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_SCRIPTwould 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.
…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.
There was a problem hiding this comment.
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 wheremainconverts after them. CJK text is where this is most likely to be noticed.①–⑳have East Asian Width A, soisCjkCharacterdoes not cover them, and手順①*注意*now stays as typed./[\p{L}\p{Nd}]/ukeeps those converting. If you prefer the current behaviour, which fits the math reading ofx²*y*, add a case to theit.eachtables 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 onmain.- CI: the red
core-tests / unit (24.x)job fails only inpackages/lexical-playground/__tests__/unit/DateTimeComponent.test.tsx(expected a day to pick), which this change does not touch;MdastShortcuts.test.tspasses 95/95 in that run.mainfixed those tests in #10001 by pinning the date the picker opens on, so updating the branch frommainshould turn the job green. A plain re-run is likely to fail the same way while it is still December.
… 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.
There was a problem hiding this comment.
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:
- Refresh the Test plan to the current head. The Before and After output in the description lists 31 tests and runs
mainat4aa11ac91a47. The branch now has 34 matching cases, since the third commit addedобʼ*єкт*,手順①*注意*and½*x*, and it now sits on a newermain. 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 matchWORD_CHARACTER(packages/lexical-mdast/src/MdastStream.ts:66) and the changeset. - 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 wheremainconverts 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.
| // (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; |
There was a problem hiding this comment.
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.
… 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)
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, socafé*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 doescafe\u0301*x*, anewith 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:
①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 inisCjkCharacter, so手順①*注意*converted after the second commit where main converts it; it converts again.\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/mdastpatch,[fix], with aVerify:paragraph).Test plan
Before
MdastStream.tsas on main (4aa11ac), with this branch's tests: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.After
The same command on this branch:
The full unit suite (
pnpm run test-unit, run at two workers):pnpm run ci-checkexits 0 (TypeScript, FlowFound 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 playgroundDateTimeComponentdate-picker tests that fail in December, which were the only failures in thecore-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