Repository navigation
Conversation
|
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.
Thanks for following up on #9921. Keeping __init__ literal inside *…*, ~~…~~, **…** and links is a nice improvement, and I reproduced locally that the four new tests fail on main and pass on this branch. There is one regression to fix before this lands.
___word___ no longer types as bold italic (packages/lexical-mdast/src/MdastStream.ts, lines 124-144, keepTypedNames)
CommonMark reads ___both___ as an _ emphasis around a __ strong (spec §6.2, rule 14). This package treats that as the underscore spelling of bold italic: see the "underscore bold italic" case in packages/lexical-mdast/src/__tests__/unit/MdastImportExport.test.ts. The inner strong passes isTypedName, so the new walk turns it back into text. Typing ___both___ now leaves an italic __both__ where main gives a bold italic both. ____init____ likewise becomes a bold __init__ instead of a bold init. Neither is a name inside another construct, and the description and changeset don't mention this change.
Skipping a __ run that touches _ on both sides fixes it and keeps all four new cases working:
if (
isTypedName(child, value) &&
child.position &&
// `___word___` is one delimiter run (bold italic), not a name.
!(
value[(child.position.start.offset ?? 0) - 1] === '_' &&
value[child.position.end.offset ?? 0] === '_'
)
) {I tried this guard locally: the @lexical/mdast unit suite still passes, ___both___ is bold italic again, ____init____ is bold init again, and _the __init___ still keeps its name. Adding ['___both___', 'both'] to the "still converts" it.each in MdastShortcuts.test.ts would pin it. The changeset's Verify: paragraph could also mention it next to __two words__.
Optional: pin the export side (packages/lexical-mdast/src/__tests__/unit/MdastShortcuts.test.ts, lines 400-425)
The #9921 cases just above also assert $convertToMarkdownString(). The new outputs export correctly today (*the \_\_init\_\_*, [see \_\_init\_\_](https://example.com)) and read back unchanged. The same assertion in the new cases would keep that round trip from regressing.
… 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)
1ccdf51 to
c39bf24
Compare
There was a problem hiding this comment.
This looks good. The new guard in keepTypedNames (packages/lexical-mdast/src/MdastStream.ts:131-140) fixes the ___word___ case from the last round: ___both___ types as bold italic and ____init____ as bold, as on main, while a name inside *…*, ~~…~~, **…** or a link keeps its underscores and exports escaped. Reproduced locally: the four new "a name inside" tests fail against main's MdastStream.ts and pass on this branch, and the whole @lexical/mdast unit suite passes.
Two optional, non-blocking suggestions:
- Re-paste the Test plan at this head. The pasted output (
Tests 4 failed | 98 skipped (102),1107 passed, "Rebased ontomainat e8fbf41") comes from the previous revision; this branch now has 104 tests inMdastShortcuts.test.ts(1109 in the package suite) and 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. - Name
___word___in the changeset'sVerify:line..changeset/mdast-typed-names-inside-constructs.md:7says__two words__inside emphasis still converts; adding that___word___still becomes bold italic would point upgraders at the one input the new guard exists for (.changeset/README.md, Behavior changes: theVerify:paragraph says what to test).
Description
Since #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 boldinit.When a construct converts, each name inside it (a
strongfrom a__run around one word of ASCII letters, digits and underscores) now becomes the text that was typed, as the review of #9921 suggested. #9921's own top-level check is refactored into the sharedisTypedNamehelper that this walk reuses.__two words__inside emphasis still converts to strong, and Markdown import is unchanged.Changeset
.changeset/mdast-typed-names-inside-constructs.md(@lexical/mdastpatch,[fix], with aVerify:paragraph).Test plan
Before
MdastStream.tsfrommain(e8fbf41), with this branch's four new tests:All four fail, the name losing its underscores:
After
The same command on this branch:
The
@lexical/mdastunit suite passes (Test Files 21 passed (21),Tests 1107 passed (1107)), and so does the full unit suite (pnpm run test-unit).pnpm run ci-checkexits 0 (TypeScript, FlowFound 0 errors, Prettier, ESLint and the changeset check). Rebased ontomainat e8fbf41 (which carries #9999).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