Unlock seamless workflows and faster delivery with our latest releases - Join the deep dive

Adding simple formatting options in normal text fields in Sanity.io

5 replies
Last updated: Dec 7, 2021
Hi Sanity-Team and -Fans! I started with sanity a while ago for a big website with gatsby as the frontend and I'm loving it 🙂 But I have one issue I can't solve. Hopefully you can point me into the right direction...

tl;dr ... is it possible to add simple formating-options in normal text-fields?
I use Portable Text for the main body of my pages and I've added a bunch of custom blocks to it for specific tasks. Like custom image/text-combinations or so. In Gatsby I use
block-content-to-react
to output those and it works like a charm.
But in some blocks I use just simple "text" fields when I need more space for userinput.

My client now asks if I can provide simple formating-options in those fields and I can't figure out how to do that without having to rebuild the whole structure and working with custom schemas and references (which would be a nightmare)

It doesn't have to be a whole new portable text/richtext field, but a simple textarea with bold, italc, link, headline-formats would be more then sufficient. I found the
markdown-input-plugin
(https://www.sanity.io/plugins/sanity-plugin-markdown ) and this could be an option. But maybe you know something more userfriendly? I could create a custom parser for it in my frontend to make ** -> strong etc.
Thanks in advance!
Dec 3, 2021, 3:55 PM
Hey Christian! In your case, you would have to use a Portable Text field to give editors control over styles like that.
What most users do is to set up two separate versions of arrays of `blockContent`: one that has all of the bells and whistles for things like articles and one that only has a few fields for cases like you're describing.
Dec 3, 2021, 6:01 PM
Thanks! I thought it was not possible to use a Portable Text within another one. But I will try that 😃
Dec 4, 2021, 8:51 AM
Crazy, it's easy peasy 😄 I looked for this a while now, but somehow I missed this solution 😄 Thanks again for pointing me into the right direction! 👍
Dec 6, 2021, 3:37 PM
Crazy, it's easy peasy 😄 I looked for this a while now, but somehow I missed this solution 😄 Thanks again for pointing me into the right direction! 👍
Dec 6, 2021, 3:37 PM
No problem – we should probably work on making this super evident.
Dec 7, 2021, 10:26 AM

Sanity– build remarkable experiences at scale

Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Was this answer helpful?