Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/code-block-patch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@platejs/code-block': patch
---

- Fixed normalizer using `setNodes` instead of `wrapNodes` for bare text children in `code_block`, which produced malformed `code_line` nodes (e.g. `{ text: "...", type: "code_line" }` instead of proper element structure). This caused syntax highlighting to only work on the first line.
- Fixed `insertBreak` not resetting the decoration cache after splitting, so new lines now get syntax highlighting immediately.
3 changes: 3 additions & 0 deletions packages/code-block/src/lib/withCodeBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ export const withCodeBlock: OverrideEditor<CodeBlockConfig> = (ctx) => {
indentDepth,
});

// Reset decoration cache so all lines get re-highlighted
resetCodeBlockDecorations(codeBlock[0] as TCodeBlockElement);

return true;
};

Expand Down
8 changes: 7 additions & 1 deletion packages/code-block/src/lib/withNormalizeCodeBlock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,13 @@ export const withNormalizeCodeBlock: OverrideEditor<CodeBlockConfig> = ({
);

if (nonCodeLine) {
editor.tf.setNodes({ type: codeLineType }, { at: nonCodeLine[1] });
// Use wrapNodes instead of setNodes to properly wrap bare text
// children in code_line elements (setNodes just adds a type
// property to text leaves, producing malformed nodes)
editor.tf.wrapNodes(
{ type: codeLineType, children: [] },
{ at: nonCodeLine[1] }
);
}
}
},
Expand Down
Loading