The Richtext field
Storyblok comes with a powerful Richtext editor that saves your content in a structured JSON format. You can customize the toolbar for each field individually and even let the user insert Storyblok blocks. If you have written your content in Markdown you have the possibility to import it using the toolbar button "Paste from Markdown".
Toolbar items
This option lets you define the toolbar items that are available for the user.
Allows only specific components to be inserted
This option lets you define the components that can be inserted by the "Add block" toolbar button.
Allow links to be open in a new tab
This option lets you set links to be open in a new tab on the link modal.
Enable custom attributes for links
This option lets you set custom attributes for your links.
Learn more about Richtext field configuration options here.
How to render Richtext data to HTML?
To render the content of the Richtext field our SDKs come with a render function.
Javascript SDK
You can easily render Richtext by using the renderRichText
function that comes with @storyblok/js:
You can set a custom Schema and component resolver globally at init time by using the richText
init option:
You can also set a custom Schema and component resolver only once by passing the options as the second parameter to renderRichText
function:
If you are using any javascript framework you can check our SDK documentation below.
Ruby Client
Following is an example of rendering a Richtext field with the Storyblok Ruby client.
If you want to render inline components you need to define a component resolver function like the following:
Then render a Richtext field like this:
Then render a Richtext field like this:
Components inside the Richtext field
What makes the Richtext field really powerful is the possibility to insert components. This lets you extend the functionality of the editor to render custom elements.
To render these components be sure to define a component resolver like shown in the section "How to render Richtext data to HTML" above.
Usually you don't want that your users insert all types of components in the Richtext field so you can restrict the type with the option "Allow only specific components to be inserted".
Migration from the Markdown field
Currently you have two options to migrate a Markdown field to Richtext field.
- Create a new field in the schema of your component, copy the content of the Markdown field and insert it with the "Paste from Markdown" button to the new field.
- Change the fieldtype of the Markdown field to a Richtext field. This will not immediately change Markdown to the Richtext format so you will need to include a check for the type in your code:
Tech stack of RT Editor
Our Richtext editor is built using TipTap Richtext editor. Check out their documentation if you want to build your own version of the Richtext editor field.