payload
payload copied to clipboard
richtext-lexical: CodeBlock markdown import prepends "undefined" and truncates info strings
Describe the Bug
The premade CodeBlock markdown converter (packages/richtext-lexical/src/features/blocks/premade/CodeBlock/converter.ts) corrupts code in two ways, through both convertMarkdownToLexical and convertLexicalToMarkdown.
- A one-line fence whose code starts with a non-word character imports with
undefinedin front of the code.```$ ls```gives codeundefined$ ls. Blocks with an empty language export to this one-line form, so they are corrupted on a round trip as well:{ language: '', code: '$ npm i -g x' }comes back asundefined$ npm i -g x, and an empty block comes back asundefined. - An info string with characters outside
\wis cut at the first such character, and the rest ends up in the code.```c++gives languagecand code++\n…. The same happens forc#,objective-candshell-session.
The file is identical on main and 3.x.
Link to the code that reproduces this issue
https://github.com/anatolykoptev/payload/commit/7e8d837e04 (a unit spec only, with no fix, on top of main 56033d9561)
Reproduction Steps
- Check out the linked commit and run
pnpm install. - Run
pnpm vitest run --project unit packages/richtext-lexical/src/features/blocks/premade/CodeBlock/converter.spec.ts. - 11 of 20 cases fail. Examples:
expected 'undefined$ ls' to be '$ ls',expected 'undefined' to be '', and forc++the code is'++\nint x;'instead of'int x;'. The controls pass (a multi-line fence with a language,```foo```, a bare multi-line fence).
Which area(s) are affected?
plugin: richtext-lexical
Environment Info
@payloadcms/richtext-lexical 4.0.0-beta.9 (main at 56033d9561); same code in 3.93.0 / 3.x
Node v22.22.3 (where the spec was run)