
Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag storeI can see your issue! You've correctly set up the decorator in your Sanity schema, but you're missing the corresponding serializer in your frontend code to render it.
In your OnePost.js, your serializers object only handles the code type, but it doesn't include anything for your custom highlight decorator. You need to add a marks section to tell @sanity/block-content-to-react how to render your highlighted text.
Here's the fix - update your serializers object:
const serializers = {
types: {
code: (props) => (
<SyntaxHighlighter
language={props.node.language}
style={coldarkDark}
showLineNumbers
lineNumberStyle={{
padding: "0 5px 0 0",
fontSize: 14,
borderRight: "1.5px solid darkgray",
marginRight: "10px",
}}
>
{props.node.code}
</SyntaxHighlighter>
),
},
marks: {
highlight: (props) => (
<span style={{ backgroundColor: "yellow" }}>{props.children}</span>
),
},
};The key addition is the marks object with your highlight decorator. The decorator name (highlight) must match what you defined in your blockContent.js schema.
Quick note on the library you're using: @sanity/block-content-to-react is deprecated in favor of @portabletext/react, which is the current recommended library. For future projects, you should consider migrating. The main difference is that it uses a components prop instead of serializers, and props.node becomes props.value.
But for now, adding the marks section should solve your highlighting issue immediately!
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.
Content operations
Content backend


The only platform powering content operations
By Industry


Tecovas strengthens their customer connections
Build and Share

Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag store