Repository navigation
Conversation
…s code ## Description CommonMark defines everything after an opening code fence as the *info string*, whose first word is conventionally the language, and states that the info string is not part of the code block's content. https://spec.commonmark.org/0.31.2/#fenced-code-blocks `CODE_START_REGEX` captures only the leading word as the language (`([\w-]+)?`). `handleImportAfterStartMatch` then takes whatever is left on the fence line and prepends it to the block's content: ```js const afterFullMatch = currentLine.slice(startMatch[0].length); if (afterFullMatch.length > 0) { linesInBetween.unshift(afterFullMatch); } ``` So the very common attribute forms produce a code block whose *first line of code* is the metadata: | markdown | imported code | | --- | --- | | ` ```js title="x" ` / `code` / ` ``` ` | `title="x"\ncode` | | ` ```ts {1,3} ` / `code` / ` ``` ` | `{1,3}\ncode` | | ` ```js showLineNumbers ` / `a` / `b` / ` ``` ` | `showLineNumbers\na\nb` | The user's code is corrupted with a line they never wrote, and it survives export, so the round trip entrenches it. This skips the remainder only when a language was actually captured — that is exactly the case where the text is a trailing info string. Two existing behaviours are deliberately untouched: - A fence with **no** language (` ``` code `) keeps its remainder as content; nothing there looks like an info string to this parser. - An **unterminated** fence keeps its lenient reading (the `'```javascript Incomplete tag'` cases in `LexicalMarkdown.test.ts`), so this only applies where a closing fence makes the block unambiguous. `CodeNode` stores a single `language`, and the serialization format is fixed, so there is nowhere to retain the rest of the info string; dropping unsupported metadata matches what the importer already does for anything else it cannot model. ## Test plan New unit test `packages/lexical-markdown/src/__tests__/unit/CodeBlockInfoString.test.ts`. The last three cases are controls for the behaviours listed above — they pass before and after. ### Before ``` $ npx vitest run packages/lexical-markdown/src/__tests__/unit/CodeBlockInfoString.test.ts × does not put a title attribute into the code content 18ms × does not put a line-highlight range into the code content 2ms × does not put a bare info-string word into the code content 1ms AssertionError: expected { language: 'js', …(1) } to deeply equal { language: 'js', text: 'code' } Tests 3 failed | 3 passed (6) ``` ### After ``` $ npx vitest run packages/lexical-markdown/src/__tests__/unit/CodeBlockInfoString.test.ts Tests 6 passed (6) $ npx vitest run packages/lexical-markdown packages/lexical-code-core Test Files 7 passed (7) Tests 467 passed (467) ```
LeSingh1
requested review from
acywatson,
etrepum,
fantactuka,
ivailop7,
potatowagon and
zurfyx
as code owners
August 9, 2026 05:28
|
@LeSingh1 is attempting to deploy a commit to the Meta Open Source Team on Vercel. A member of the Team first needs to authorize it. |
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 defines everything after an opening code fence as the info string,
whose first word is conventionally the language, and states that the info
string is not part of the code block's content.
https://spec.commonmark.org/0.31.2/#fenced-code-blocks
CODE_START_REGEXcaptures only the leading word as the language(
([\w-]+)?).handleImportAfterStartMatchthen takes whatever is left on thefence line and prepends it to the block's content:
So the very common attribute forms produce a code block whose first line of
code is the metadata:
```js title="x"/code/```title="x"\ncode```ts {1,3}/code/```{1,3}\ncode```js showLineNumbers/a/b/```showLineNumbers\na\nbThe user's code is corrupted with a line they never wrote, and it survives
export, so the round trip entrenches it.
This skips the remainder only when a language was actually captured — that is
exactly the case where the text is a trailing info string. Two existing
behaviours are deliberately untouched:
``` code) keeps its remainder as content;nothing there looks like an info string to this parser.
'```javascript Incomplete tag'cases inLexicalMarkdown.test.ts), so thisonly applies where a closing fence makes the block unambiguous.
CodeNodestores a singlelanguage, and the serialization format is fixed,so there is nowhere to retain the rest of the info string; dropping unsupported
metadata matches what the importer already does for anything else it cannot
model.
Test plan
New unit test
packages/lexical-markdown/src/__tests__/unit/CodeBlockInfoString.test.ts.The last three cases are controls for the behaviours listed above — they pass
before and after.
Before
After