Working with Rich Text
Rich Text in Val
Val's rich text is based on semantic HTML5 and provides a structured way to define prose. The output is HTML JSON nodes, which means it is easy to understand and transform. The ValRichText component makes it easy to render and theme rich text.
Defining Rich Text Schema
Use s.richtext() to define a rich text field with configurable formatting options:
Rich Text output
Rich text is represented as an array of block elements, where each element has a tag and children:
Rendering Rich Text
Use the ValRichText component to render rich text in your React components:
Theme Requirements
You can choose to render rich text without a theme if you don't need custom styling. However, if you provide a theme, TypeScript will require you to theme all the features you've enabled in your schema.
For example, if your schema includes bold, italic, and h1, your theme must provide styling for all three. This type-checking ensures you don't forget to update your theme when you extend your rich text schema with new features.
Available Options
Rich text supports three categories of formatting:
Styles: bold, italic, lineThrough, underline
Block elements: p, h1-h6, ul, ol, blockquote, code
Inline elements: a (links), img (images)