Skip to content

fix(code-block): fix normalizer and insertBreak for syntax highlighting#4837

Open
ttillberg wants to merge 1 commit intoudecode:mainfrom
ttillberg:fix/code-block-syntax-highlighting
Open

fix(code-block): fix normalizer and insertBreak for syntax highlighting#4837
ttillberg wants to merge 1 commit intoudecode:mainfrom
ttillberg:fix/code-block-syntax-highlighting

Conversation

@ttillberg
Copy link

Summary

  • Normalizer: Use wrapNodes instead of setNodes to properly wrap bare text children in code_line elements. setNodes was producing malformed nodes like { text: "...", type: "code_line" } instead of proper { type: "code_line", children: [{ text: "..." }] } structure.
  • insertBreak: Call resetCodeBlockDecorations after splitting to bust the WeakMap cache and force re-highlighting on all lines.

These two fixes together resolve the issue where only the first line of a code block gets syntax highlighting.

Fixes #4520
Related: #4399, #3407

Test plan

  • Open the code block demo and verify syntax highlighting works on all lines
  • Type multiple lines in a code block and confirm each line is highlighted
  • Press Enter in a code block and verify the new line gets syntax highlighting
  • Test with autoformat (e.g. typing ``` to create a code block) and verify all lines highlight correctly

…structure

use wrapNodes instead of setNodes in normalizer to properly wrap bare text
children in code_line elements. reset decoration cache after insertBreak so
new lines get syntax highlighting immediately.

- normalizer: wrapNodes instead of setNodes for bare text in code_block
- insertBreak: call resetCodeBlockDecorations after splitting

fixes udecode#4520

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@codesandbox
Copy link

codesandbox bot commented Feb 9, 2026

Review or Edit in CodeSandbox

Open the branch in Web EditorVS CodeInsiders

Open Preview

@dosubot dosubot bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Feb 9, 2026
@vercel
Copy link

vercel bot commented Feb 9, 2026

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

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
plate Ignored Ignored Feb 9, 2026 3:58pm

Request Review

@changeset-bot
Copy link

changeset-bot bot commented Feb 9, 2026

🦋 Changeset detected

Latest commit: 76306d3

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

This PR includes changesets to release 1 package
Name Type
@platejs/code-block 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

@dosubot dosubot bot added bug Something isn't working plugin:code-block labels Feb 9, 2026
@zbeyens
Copy link
Member

zbeyens commented Feb 9, 2026

Thanks for the PR! Could you fix the test CI?

@zbeyens zbeyens requested a review from a team March 13, 2026 05:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working plugin:code-block size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Code block formatting causing syntax highlight to be lost

2 participants