How to render a special formatted inline text in blockContent in Sanity.io
Yes, you can absolutely render a custom type as inline text with special formatting! What you need is an inline block object, which is different from both annotations and regular block-level objects.
Here's how to set it up:
In your schema, add your custom type to the of array inside the block definition (not at the array level):
{
name: 'content',
type: 'array',
of: [
{
type: 'block',
// This is the key - put inline objects in the block's 'of' property
of: [
{
type: 'myInlineType',
name: 'myInlineType',
title: 'My Inline Type',
fields: [
// Your document fields here
{name: 'value', type: 'string'},
{name: 'metadata', type: 'object', fields: [...]}
]
}
]
}
]
}The critical difference is:
- Block-level objects: Added to the array's
ofproperty → renders full-width - Inline objects: Added to the block's
ofproperty → renders inline with text - Annotations: Lightweight marks on text spans → can't have complex structure
This way, your custom type will appear inline in the editor (you can insert it via the Insert menu while editing text), but you still get the full power of managing it as a proper document with all the fields you need.
You can also customize how it renders in the Studio by adding a custom inlineBlock component to control its appearance in the editor.
When rendering on the front end, you'll need to handle this inline object type in your Portable Text serializer to display it with your special formatting.
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.