How to render code blocks with SanityContent components and style them properly.

2 replies
Last updated: Apr 15, 2024
Hey team, I’ve been scouring the internet for this without much luck – does anyone know how to render code blocks with SanityContent components? I added code blocks to my richtext input, but they’re getting rendered as plain paragraphs without any distinguishing characteristics, making it impossible to style them.
Apr 15, 2024, 2:46 PM
Is this on your frontend or in the Studio?
Apr 15, 2024, 5:08 PM
Both, though I’ve now figured this one out. Had to add some additional options to the code-input blok aaand set up serializers with a custom component.
Apr 15, 2024, 7:50 PM

Sanity – Build the way you think, not the way your CMS thinks

Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.

Was this answer helpful?