Skip to content

fix(markdown): split code_block lines on CRLF and CR - #5328

Merged
zbeyens merged 3 commits into
udecode:mainfrom
yulman2207:codex/fix-markdown-crlf-code-block
Nov 4, 2026
Merged

zbeyens merged 3 commits into
udecode:mainfrom
yulman2207:codex/fix-markdown-crlf-code-block

Conversation

@yulman2207

@yulman2207 yulman2207 commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor
  • Auto release

Fixes #5322

Problem

For a fenced code block with CRLF line endings, deserializeMd kept a trailing \r on every code_line except the last, and serializeMd then wrote CRLF inside an LF fence.

Fix

The code_block deserialize rule split mdastNode.value on \n only. It now splits on \r\n, \r or \n, so CRLF/CR input gives the same value and serialized output as its LF version. LF input is unchanged.

Tests

Added codeBlockLineEndings.spec.ts covering CRLF and CR input: value equals the LF value, no \r in the value, serialize output equals the LF output. Patch changeset for @platejs/markdown included.

Verification

I have not run the spec or pnpm check locally (full monorepo checkout wasn't possible in my environment); relying on CI. The split pattern was checked in plain Node.

mdast keeps the original line endings in a fenced code value, so splitting on
\n alone left a trailing \r on every code_line but the last and serialization
wrote mixed line endings inside the fence. Split on \r\n, \r or \n so CRLF
input produces the same value as its LF version.

Fixes udecode#5322
@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: 96791d9

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 2 commits November 1, 2026 13:28
Move the fix from the code block rule to `markdownToSlateNodes`, so
paragraphs, quotes, list items, inline code and math lose the carriage
return too. The test now checks that each line ending parses to the
value of its LF version.

Refs plate#5322 and plate#5323
@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 CRLF and CR cases.
  • Changed
    • The fix moved from the code_block rule to markdownToSlateNodes, so paragraphs, blockquotes, list items, inline code and math lose the carriage return too. That also fixes plate#5323 on main.
    • The test moved into deserializeMd.spec.ts. Each line ending's document, a fenced code block and a two-line paragraph, must parse to the value of its LF version.
    • The changeset names CR as well as CRLF and says the value changed, not serializeMd.
  • Dropped
    • CODE_LINE_BREAK_REGEX and the code_block rule change, so defaultRules.ts matches main.
    • The test's check that the value holds no CR and its check of the serialized fence. The value comparison already fails on both bugs.

Verification

  • The new test fails on the PR head for the paragraph and passes on my commit, for CRLF and CR.
  • The @platejs/markdown suite, typecheck and lint pass on my commit.

@zbeyens
zbeyens merged commit b9de659 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