Skip to content

[lexical-markdown] Bug Fix: Escape ordered-list pattern in bullet list item export#8311

Merged
etrepum merged 3 commits intofacebook:mainfrom
Sathvik-Chowdary-Veerapaneni:backslash-escape-list-7824
Apr 22, 2026
Merged

[lexical-markdown] Bug Fix: Escape ordered-list pattern in bullet list item export#8311
etrepum merged 3 commits intofacebook:mainfrom
Sathvik-Chowdary-Veerapaneni:backslash-escape-list-7824

Conversation

@Sathvik-Chowdary-Veerapaneni
Copy link
Copy Markdown
Contributor

Description

When a bullet or check list item starts with a number-dot-space pattern (e.g. 1. foo), switching between WYSIWYG and markdown mode causes the exporter to double-escape the backslash: 1\. foo becomes 1\\. foo on each round-trip.

The root cause is in $listExport: the exporter outputs the list item text as-is without escaping the ordered-list pattern. On re-import, unescapeText correctly strips the backslash from 1\., but the exporter never re-adds it, causing the inline escape logic to double the existing backslash instead.

Fixed by escaping the dot when a non-number list item's text starts with \d+\.\s, producing 1\. foo in the markdown output.

Closes #7824

Test plan

Before

- 1\. foo

After WYSIWYG round-trip becomes:

- 1\\. foo

After

Stable round-trip — - 1\. foo stays - 1\. foo.

Added a unit test for bullet list items starting with ordered-list patterns.

All existing tests pass (329 markdown tests, 2742 total).

…t item export

When a bullet or check list item starts with a number-dot-space pattern
(e.g. "1. foo"), the markdown exporter now escapes the dot to prevent
double-escaping on round-trip. Previously, switching between WYSIWYG
and markdown mode would turn "1\. foo" into "1\\. foo".

Closes facebook#7824
@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 8, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
lexical Ready Ready Preview, Comment Apr 21, 2026 5:43pm
lexical-playground Ready Ready Preview, Comment Apr 21, 2026 5:43pm

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Apr 8, 2026
@etrepum etrepum added the extended-tests Run extended e2e tests on a PR label Apr 12, 2026
skipExport: true,
},
{
// Bullet list item starting with number-dot pattern should be escaped (Regression #7824)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Bullet list item starting with number-dot pattern should be escaped (Regression #7824)
// Bullet list item starting with number-dot pattern should be escaped (#7824)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

output.push(indent + prefix + exportChildren(listItemNode));
let childrenText = exportChildren(listItemNode);
if (listType !== 'number') {
childrenText = childrenText.replace(/^(\d+)(\.\s)/, '$1\\$2');
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should allow for some spaces before the number as well

Suggested change
childrenText = childrenText.replace(/^(\d+)(\.\s)/, '$1\\$2');
childrenText = childrenText.replace(/^(\s{0,3}\d+)(\.\s)/, '$1\\$2');

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Applied both — dropped the label and updated the regex to handle leading spaces.

@etrepum etrepum added this pull request to the merge queue Apr 22, 2026
Merged via the queue into facebook:main with commit 30b7e29 Apr 22, 2026
38 checks passed
@etrepum etrepum mentioned this pull request Apr 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. extended-tests Run extended e2e tests on a PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: backslash injection in numbered list edge case

2 participants