Repository navigation
Conversation
…ted code block ## Description An opening code fence may be indented by up to three spaces. CommonMark then requires that indentation to be removed from the block's content: > If the leading code fence is indented N spaces, then up to N spaces of > indentation are removed from each line of the content (if present). > https://spec.commonmark.org/0.31.2/#fenced-code-blocks `CODE_START_REGEX` already accepts a leading-whitespace run and captures it as part of `startMatch[1]`, and `CODE_END_REGEX` accepts an indented closing fence, so an indented block is imported as a code block. But `CODE.replace` only ever used `startMatch[1].trim()` to derive the fence string and never looked at the indentation, so every content line kept it: ``` ```js code ``` ``` imported as a code block whose text is `" code"` rather than `"code"`. The indentation is dropped from the fence lines on export but kept in the content, so the block also comes back wider on every markdown round trip. This computes the fence indent from the whitespace `startMatch[1]` already carries, and removes up to that many leading space/tab characters from each content line. "Up to" matters: content indented less than the fence is left alone rather than having non-whitespace removed, and indentation *relative* to the fence is preserved. A fence with no indentation is unaffected, so code blocks that intentionally start with indented lines still keep it. ## Test plan New unit test `packages/lexical-markdown/src/__tests__/unit/CodeBlockFenceIndent.test.ts`. ### Before ``` $ npx vitest run packages/lexical-markdown/src/__tests__/unit/CodeBlockFenceIndent.test.ts × removes the fence indentation from the content 7ms × preserves indentation relative to the fence 1ms × removes at most the fence indentation 1ms × handles a tab-indented fence 1ms AssertionError: expected ' code' to be 'code' // Object.is equality AssertionError: expected ' a\n b' to be 'a\n b' // Object.is equality AssertionError: expected 'a\n b' to be 'a\nb' // Object.is equality AssertionError: expected '\tcode' to be 'code' // Object.is equality Tests 4 failed | 1 passed (5) ``` ### After ``` $ npx vitest run packages/lexical-markdown/src/__tests__/unit/CodeBlockFenceIndent.test.ts Test Files 1 passed (1) Tests 5 passed (5) $ npx vitest run packages/lexical-markdown packages/lexical-code-core packages/lexical-code-prism packages/lexical-code-shiki Test Files 13 passed (13) Tests 643 passed (643) ```
LeSingh1
requested review from
acywatson,
etrepum,
fantactuka,
ivailop7,
potatowagon and
zurfyx
as code owners
August 9, 2026 05:09
|
@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
An opening code fence may be indented by up to three spaces. CommonMark then
requires that indentation to be removed from the block's content:
CODE_START_REGEXalready accepts a leading-whitespace run and captures it aspart of
startMatch[1], andCODE_END_REGEXaccepts an indented closingfence, so an indented block is imported as a code block. But
CODE.replaceonly ever used
startMatch[1].trim()to derive the fence string and neverlooked at the indentation, so every content line kept it:
$ npx vitest run packages/lexical-markdown/src/tests/unit/CodeBlockFenceIndent.test.ts
AssertionError: expected ' code' to be 'code' // Object.is equality
AssertionError: expected ' a\n b' to be 'a\n b' // Object.is equality
AssertionError: expected 'a\n b' to be 'a\nb' // Object.is equality
AssertionError: expected '\tcode' to be 'code' // Object.is equality
$ npx vitest run packages/lexical-markdown/src/tests/unit/CodeBlockFenceIndent.test.ts
Test Files 1 passed (1)
Tests 5 passed (5)
$ npx vitest run packages/lexical-markdown packages/lexical-code-core packages/lexical-code-prism packages/lexical-code-shiki
Test Files 13 passed (13)
Tests 643 passed (643)