Repository navigation
Conversation
…Mark does ## Description CommonMark treats everything after an opening code fence, trimmed, as the info string, and its first word is the language. That holds whether or not the block is closed: an unclosed fence runs to the end of the document. Lexical read the language only when it came right after the backticks, and kept the rest of the line out of the code only when the block was closed. So ```` ``` js ```` imported with no language and `js` as the first line of code, and an unclosed ```` ```js title=x ```` put `title=x` into the code. The info string then stayed in the code on every save. This change: - lets `CODE_START_REGEX` accept whitespace between the fence and the language, so ```` ``` js ```` is a `js` block; - reads the rest of an unclosed fence's opening line as metadata, the same way a closed fence's is read, and keeps it on export (```` ```js title=x ````). A closed ```` ```js title="x" ```` fence, `` ```js `` with nothing after it, a bare ```` ``` ```` fence and the single-line `` ```code``` `` form are unchanged. ```` ``` code ```` / `more` / ```` ``` ```` now becomes language `code` with code `more`, as in CommonMark, so the tests that asserted the old behaviour are updated. Closes meta#9406 ## Test plan ### Before `pnpm exec vitest --project unit --no-watch packages/lexical-markdown`, with the updated tests and the original `MarkdownTransformers.ts`: ``` × treats text after the opening fence as the info string 16ms × keeps a blank first line of an unterminated fence with an info string 5ms × reads a language that follows whitespace after the fence 19ms × keeps the metadata of a fence with whitespace before the language 6ms × reads the info string of an unterminated fence 4ms × reads the language of an unterminated fence after whitespace 3ms × can import "```javascript Incomplete tag" 14ms × can import "```javascript Incomplete multiline\n\nTag" 4ms Test Files 3 failed | 5 passed (8) Tests 8 failed | 690 passed (698) ``` ### After ``` Test Files 8 passed (8) Tests 698 passed (698) ``` `pnpm exec vitest --project unit --no-watch packages/lexical-markdown packages/lexical-mdast packages/lexical-playground/__tests__/unit`: ``` Test Files 45 passed (45) Tests 1246 passed (1246) ``` `tsc`, ESLint and Prettier pass on the changed files. The Markdown shortcut uses the same regular expression, and typing ```` ``` ```` plus a space still gives the same match, but this was not tried in a browser, and the E2E suites were not run.
nakultt
requested review from
acywatson,
fantactuka and
zurfyx
as code owners
October 28, 2026 09:15
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
CommonMark treats everything after an opening code fence, trimmed, as the
info string, and its first word is the language. That holds whether or not
the block is closed: an unclosed fence runs to the end of the document.
Lexical read the language only when it came right after the backticks, and
kept the rest of the line out of the code only when the block was closed.
So
``` jsimported with no language andjsas the first line ofcode, and an unclosed
```js title=xputtitle=xinto the code.The info string then stayed in the code on every save.
This change:
CODE_START_REGEXaccept whitespace between the fence and thelanguage, so
``` jsis ajsblock;way a closed fence's is read, and keeps it on export
(
```js title=x).A closed
```js title="x"fence,```jswith nothing after it,a bare
```fence and the single-line```code```form areunchanged.
``` code/more/```now becomes languagecodewith codemore, as in CommonMark, so the tests that asserted theold behaviour are updated.
Closes #9406
Test plan
Before
pnpm exec vitest --project unit --no-watch packages/lexical-markdown, withthe updated tests and the original
MarkdownTransformers.ts:After
pnpm exec vitest --project unit --no-watch packages/lexical-markdown packages/lexical-mdast packages/lexical-playground/__tests__/unit:tsc, ESLint and Prettier pass on the changed files. The Markdown shortcutuses the same regular expression, and typing
```plus a spacestill gives the same match, but this was not tried in a browser, and the
E2E suites were not run.