Repository navigation
Conversation
…reak
## Description
`parseMarkdownHardLineBreak` treats any line ending in a backslash as a hard
line break:
```js
if (line.endsWith('\\')) {
return [line.slice(0, -1), '\\'];
}
```
CommonMark only gives a trailing backslash that meaning when the backslash is
not itself escaped. `foo\\` is a backslash escape — a literal `\` followed by
an ordinary (soft) line ending — so only an **odd**-length run of trailing
backslashes is a hard line break.
https://spec.commonmark.org/0.31.2/#backslash-escapes
Because the parser cannot tell `foo\` from `foo\\`, the final backslash is
consumed as a line-break marker and removed from the text. With
`shouldMergeAdjacentLines`, `normalizeMarkdown` also refuses to merge the two
lines, since it asks the same function whether the previous line ended in a
hard line break:
```
input: foo\\
bar
expected: one paragraph, text `foo\ bar`
actual: two lines, text `foo` + hard break + `bar` (the `\` is gone)
```
This counts the trailing backslash run and only reports a hard line break for
an odd length. The lone-backslash and two-space forms are unchanged.
Note this fixes the merging path, where `normalizeMarkdown` joins the lines
before any line-break node is built. Without `shouldMergeAdjacentLines` the
marker is extracted from a TextNode whose escapes have already been resolved
by `importTextTransformers`, so `foo\\` and `foo\` are genuinely
indistinguishable at that point; disambiguating those would mean moving
hard-line-break detection ahead of unescaping, which is a larger change and is
left alone here.
## Test plan
New unit test `packages/lexical-markdown/src/__tests__/unit/EscapedBackslashHardLineBreak.test.ts`,
covering the parser directly, `normalizeMarkdown`, and the imported text. The
lone-backslash and two-space cases are included as controls — they pass before
and after.
### Before
```
$ npx vitest run packages/lexical-markdown/src/__tests__/unit/EscapedBackslashHardLineBreak.test.ts
× does not treat an escaped backslash as a hard line break 3ms
× merges a line ending in an escaped backslash with the next line 2ms
× keeps the literal backslash in the imported text 5ms
AssertionError: expected [ 'foo\', '\' ] to be null // Object.is equality
AssertionError: expected 'foo\\\nbar' to be 'foo\\ bar' // Object.is equality
AssertionError: expected 'foo\nbar' to be 'foo\ bar' // Object.is equality
Tests 3 failed | 4 passed (7)
```
### After
```
$ npx vitest run packages/lexical-markdown/src/__tests__/unit/EscapedBackslashHardLineBreak.test.ts
Tests 7 passed (7)
$ npx vitest run packages/lexical-markdown packages/lexical-code-core
Test Files 8 passed (8)
Tests 474 passed (474)
```
LeSingh1
requested review from
acywatson,
etrepum,
fantactuka,
ivailop7,
potatowagon and
zurfyx
as code owners
August 9, 2026 05:26
|
@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
parseMarkdownHardLineBreaktreats any line ending in a backslash as a hardline break:
CommonMark only gives a trailing backslash that meaning when the backslash is
not itself escaped.
foo\\is a backslash escape — a literal\followed byan ordinary (soft) line ending — so only an odd-length run of trailing
backslashes is a hard line break.
https://spec.commonmark.org/0.31.2/#backslash-escapes
Because the parser cannot tell
foo\fromfoo\\, the final backslash isconsumed as a line-break marker and removed from the text. With
shouldMergeAdjacentLines,normalizeMarkdownalso refuses to merge the twolines, since it asks the same function whether the previous line ended in a
hard line break:
This counts the trailing backslash run and only reports a hard line break for
an odd length. The lone-backslash and two-space forms are unchanged.
Note this fixes the merging path, where
normalizeMarkdownjoins the linesbefore any line-break node is built. Without
shouldMergeAdjacentLinesthemarker is extracted from a TextNode whose escapes have already been resolved
by
importTextTransformers, sofoo\\andfoo\are genuinelyindistinguishable at that point; disambiguating those would mean moving
hard-line-break detection ahead of unescaping, which is a larger change and is
left alone here.
Test plan
New unit test
packages/lexical-markdown/src/__tests__/unit/EscapedBackslashHardLineBreak.test.ts,covering the parser directly,
normalizeMarkdown, and the imported text. Thelone-backslash and two-space cases are included as controls — they pass before
and after.
Before
After