Presenting Block Text
Sanity represents block text as vanilla arrays. The studio simply renders the array as a text editor if
block is allowed in the array as a type. Now editors might think they're working on something like a free form
contenteditable text area, but they're really defining a strict, validated data structure.
Have a look at the reference documentation for block text for more on how you define the schema.
This has some pretty great benefits:
- You get to precisely define a schema for text. Decide exactly what formatting is allowed where.
- Intersperse data objects with text blocks: don't add a map as an image. Add a
geopointto your array and install the @sanity/google-maps-input. Editors get a map control and you keep the location around as data.
- Define custom annotations – footnotes, comments, etc.
This way of thinking about text makes all kinds of good things happen: no HTML or free form markup in your text means no more weird issues with text pasted from Word. It also means you can defer all decisions about display till you use it on a front-end.
The only drawback might be that you will need to convert the array of content to something you can render. We have helpers for this for different languages and platforms.
Block Content to HTML
Block Content to React
Block Content to Hyperscript
Need to serialize to something not listed here in a language we don't cover? Ping us on Gitter and let us know.