Skip to content

fix(markdown): keep soft break after inline nodes on deserialize - #5329

Merged
zbeyens merged 5 commits into
udecode:mainfrom
yulman2207:codex/fix-markdown-soft-break-after-inline
Nov 4, 2026
Merged

zbeyens merged 5 commits into
udecode:mainfrom
yulman2207:codex/fix-markdown-soft-break-after-inline

Conversation

@yulman2207

@yulman2207 yulman2207 commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor
  • Auto release

Fixes #5321

Problem

deserializeMd dropped a soft line break right after a link, mark or inline code (a [link](x)\nb became linkb). Since #4200 the default text rule stripped a leading \n from every text node.

Fix

The leading newline is now dropped only when the previous sibling is a <br> html node (the case the strip was added for, e.g. > line1<br>\n> line2). The text rule keeps its value as is.

Tests

Added softBreakAfterInline.spec.ts: link, emphasis, inline code and plain text keep \n, and the blockquote <br> case still gives a single \n. Patch changeset included.

Verification

Not run locally (full monorepo checkout wasn't possible in my environment); relying on CI.

The default text rule stripped a leading newline from every text node, which
joined the words around a soft break that follows a link, mark or inline code.
Drop the newline only when the previous sibling is a <br> node, so the
blockquote <br> case still yields a single newline.

Fixes udecode#5321
@codesandbox

codesandbox Bot commented Nov 1, 2026

Copy link
Copy Markdown

Review or Edit in CodeSandbox

Open the branch in Web Editor • VS Code • Insiders

Open Preview

@changeset-bot

changeset-bot Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 97d0b3f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@platejs/markdown Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

yulman2207 and others added 4 commits November 1, 2026 13:58
…aragraphs

The <br> inside a paragraph reaches the deserializer as an mdx br element, and
the root-level <br /> paragraph relied on the text rule's strip. Treat an mdx
br like an html br, and build the empty paragraph text as '' directly.
The text rule no longer strips a leading newline, so the root-level <br />
paragraph must not start with one.
The check that drops the line ending after a `<br>` now runs for the
children of bold, italic and strikethrough, and it accepts a br tag
with attributes, as `main` did before. Before, `**a<br>\nb**` gave two
line breaks.

Refs plate#5321
@zbeyens
zbeyens requested a review from a team November 4, 2026 13:50
@zbeyens

zbeyens commented Nov 4, 2026

Copy link
Copy Markdown
Member

My commits after yours

On top of the PR

  • Kept
    • The rule: drop the line ending at the start of a text node only when a br tag comes right before it.
    • The link, emphasis, inline code and blockquote br cases.
  • Changed
    • The check lives in internal/dropNewlineAfterBr.ts and runs for the children of bold, italic and strikethrough too. Before, **a<br>\nb** gave two line breaks.
    • A br at the end of bold, italic or link text counts too, so **a<br>**\nb gives one line break, as on main before the PR.
    • The br test accepts attributes, such as <br class="x"> under withoutMdx, as main did before the PR. That case has its own test.
  • Dropped
    • The plain-text case. A text node with no leading line ending cannot fail on any bug in this change.

Verification

  • The spec fails on the PR head for the bold and attribute br cases. A probe showed two breaks for a br at the end of bold, italic or link text before this commit. All 8 tests pass on my commit.
  • The @platejs/markdown suite, its typecheck, its slow tests and Biome pass on my commit.
  • With PR 5328's commit applied too, a br tag before a CRLF line ending gives one break.

@zbeyens
zbeyens merged commit 9bfec80 into udecode:main Nov 4, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants