Simplify your stack and build anything. Or everything.
Build tomorrow’s web with a modern solution you truly own.
Code-based nature means you can build on top of it to power anything.
It’s time to take back your content infrastructure.

Code blocks in rich text editor.

default discord avatar
now_i_am_a_strawberry2 years ago
5

Hi, I created my personal site that has blogging functionality with Payload and I'm loving it. The integration was super easy and coming from Wordpress, the UI feels super nice.



My question is,

How to have code blocks in rich text editor?

I'd like to render code blocks in my blog posts. Currently, I'm using the inline code leaf, which isn't optimal for my case because of obvious reasons. A plus would be if it had syntax highlighting.



I suppose it should be done like this. (

https://payloadcms.com/docs/fields/rich-text#example

). Example from the docs.


  {
    name: 'codeblock',
    Button: CodeBlockButton,
    Element: CodeBlockElement,
    plugins: []
  }


How should the

CodeBlockElement

and

CodeBlockButton

look like? (If that's how you achieve the code block functionality 😅 )



Can you please share some info on how to do this? Thanks in advance.


You're doing an amazing work. The best experience with CMS I've had. 👌

Star on GitHub

Star

Chat on Discord

Discord

online

Can't find what you're looking for?

Get dedicated engineering support directly from the Payload team.