#How do i add a code block to the lexical editor in version 3.0 of Payload?

1 messages · Page 1 of 1 (latest)

viscid arch
#

I am currently exploring the Payload version 3 repository (payload-3.0-demo) on GitHub, and it's been a fantastic experience so far. The only issue I'm encountering is that the Lexical editor doesn't natively support a code block feature, and I'm struggling to integrate this functionality. My goal is to create a frontend blog that includes code blocks with syntax highlighting and a copy button in the top right corner.

also it would be really nice if i could specify the language, highlight specific lines in the code, add line count etc. Does anyone know of a solution to this?

oak obsidianBOT
tiny rover
#

You can use the Blocks feature and add a code field for that. Using a custom code field component you can integrate a button that acts as a language picker.

You can find an example that does exactly that here: https://github.com/payloadcms/payload/blob/feat/lexical-mdx/test/lexical-mdx/collections/Posts/index.ts#L64

GitHub

Payload is the open-source, fullstack Next.js framework, giving you instant backend superpowers. Get a full TypeScript backend and admin panel instantly. Use Payload as a headless CMS or for buildi...