Adding simple formatting options in normal text fields in Sanity.io
I totally understand your situation! You want simple formatting in regular text fields without the complexity of full Portable Text blocks. Let me share some practical options:
The Short Answer: Yes, there are a few ways to add simple formatting to text fields, and you're on the right track with the markdown plugin!
Option 1: Use minimal Portable Text configuration
Instead of using the basic string type, you can use an array type with a stripped-down Portable Text configuration. This gives you a textarea-like field with just the formatting options you need:
{
name: 'simpleText',
type: 'array',
of: [{
type: 'block',
styles: [{title: 'Normal', value: 'normal'}],
lists: [],
marks: {
decorators: [
{title: 'Bold', value: 'strong'},
{title: 'Italic', value: 'em'}
],
annotations: [
{
name: 'link',
type: 'object',
title: 'Link',
fields: [{name: 'href', type: 'url'}]
}
]
}
}]
}This approach keeps you in the Portable Text ecosystem, so you can continue using block-content-to-react in Gatsby without additional parsing. You're just limiting which formatting options appear in the editor by customizing the styles, marks.decorators, and marks.annotations arrays.
Option 2: Markdown Plugin (Your Idea!)
The markdown plugin you found is definitely a solid choice! It's more user-friendly than raw markdown for many clients. You'd just need to add a markdown parser in your Gatsby frontend (like remark or marked) to convert it to HTML.
Option 3: Simple HTML in String Fields
Some folks allow basic HTML in string fields and sanitize it on the frontend, but this is generally not recommended as it's harder to validate and can be a security concern.
My Recommendation:
Go with Option 1 (minimal Portable Text config). Here's why:
- No need to rebuild your structure - just change the field type from
stringto the array configuration above - Reuses your existing
block-content-to-reactsetup in Gatsby - Gives clients a WYSIWYG experience
- Keeps content structured and safe
- Easy to extend later if needed
You can customize exactly which formatting options appear by adjusting what you include in the schema. Want to add headings? Add more items to the styles array. Need lists? Configure the lists array. This way, your clients get the simple formatting they need without the full complexity of your main body content blocks.
Hope this helps! π
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.