Skip to content

[lexical-markdown] Bug Fix: Preserve markdown hard line breaks during import when newlines are preserved#8265

Merged
etrepum merged 5 commits intofacebook:mainfrom
joshjryan:fix-4843
Apr 1, 2026
Merged

[lexical-markdown] Bug Fix: Preserve markdown hard line breaks during import when newlines are preserved#8265
etrepum merged 5 commits intofacebook:mainfrom
joshjryan:fix-4843

Conversation

@joshjryan
Copy link
Copy Markdown
Contributor

@joshjryan joshjryan commented Mar 27, 2026

Description

I noticed that hard line breaks in markdown could get lost after an import and edit flow, when the markdown is toggled into the editor and then saved back out.

(this is my first contribution to this project, so please let me know if I should be doing anything differently)

This PR keeps hard-break intent intact when newline preservation is enabled:

Handles two trailing spaces before a newline as a hard break marker during import line merge handling.

  • Keeps existing backslash hard-break behavior aligned in the same path.
  • Adds focused unit coverage for both hard-break forms so round-trip behavior is explicit:
    -- foo followed by two spaces and a newline
    -- foo followed by backslash and a newline

I also added coverage around normalization behavior so the merge path is tested directly.

Closes #4843

Test plan

Before

  • Hard line breaks could be lost in markdown import/export round trips in newline-preserving workflows.
  • No dedicated round-trip test for backslash hard breaks in that path.
  • No dedicated test asserting two-space hard-break handling in that same path.

###After

  • Added unit test coverage that round-trips both hard-break forms with newline preservation enabled:
    -- markdown hard line break import: preserves hard line break when shouldPreserveNewLines is true
    -- markdown hard line break import: preserves backslash hard line break when shouldPreserveNewLines is true
  • Added normalization coverage for hard-break-adjacent merge behavior.

@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 Mar 27, 2026
@vercel
Copy link
Copy Markdown

vercel bot commented Mar 27, 2026

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

Project Deployment Actions Updated (UTC)
lexical Ready Ready Preview, Comment Mar 28, 2026 9:40pm
lexical-playground Ready Ready Preview, Comment Mar 28, 2026 9:40pm

Request Review

@joshjryan joshjryan changed the title Preserve hard line breaks in markdown when shouldPreserveNewLines is true [lexical-markdown] Bug Fix: Preserve markdown hard line breaks during import when newlines are preserved Mar 27, 2026
@etrepum
Copy link
Copy Markdown
Collaborator

etrepum commented Mar 28, 2026

This PR doesn't look like it solves the issue that it claims to close, this one only changes the behavior of trailing backslash and not leading/trailing whitespace

@joshjryan
Copy link
Copy Markdown
Contributor Author

This PR doesn't look like it solves the issue that it claims to close, this one only changes the behavior of trailing backslash and not leading/trailing whitespace

You're right, I missed the part of the request about leading whitespace. I was just focused on trailing whitespace (for indicating hard line-breaks with trailing double spaces).

I can modify this to also account for leading white space.

Copy link
Copy Markdown
Collaborator

@etrepum etrepum left a comment

Choose a reason for hiding this comment

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

This seems reasonable at least as far as the existing test suite goes

@etrepum etrepum added this pull request to the merge queue Apr 1, 2026
Merged via the queue into facebook:main with commit 8056854 Apr 1, 2026
34 checks passed
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: Importing from Markdown strips leading/trailing spaces

2 participants