storyblok-markdown-richtext
v1.0.3
Published
A library to transform markdown to Richtext data
Downloads
12,720
Readme
Storyblok Markdown to Richtext converter
Do you need help converting HTML or markdown into Storyblok's richtext format?
Here's how to use it:
Usage
Install the npm module storyblok-markdown-richtext
by running:
$ yarn add storyblok-markdown-richtext # npm install storyblok-markdown-richtext
And use the functions where you need:
import { markdownToRichtext } from 'storyblok-markdown-richtext'
const richtextData = markdownToRichtext(`# Hello World`)
// ...
To convert HTML to richtext, you'll also need an HTML to markdown converter. In the example below, we use turndown.
import TurndownService from 'turndown'
import { markdownToRichtext } from 'storyblok-markdown-richtext'
const turndownService = new TurndownService()
const richtextData = markdownToRichtext(
turndownService.turndown('<h1>Hello world!</h1>')
)
markdownToRichtext
This function transforms your HTML or markdown data into a richtext JSON object. Here's an example:
import { markdownToRichtext } from 'storyblok-markdown-richtext'
const richtextObject = markdownToRichtext(`# Hello World`)
The resulting richtext object will look like this:
{
type: 'doc',
content: [
{
type: 'heading',
attrs: {
level: 1
},
content: [
{
text: 'Hello World',
type: 'text'
}
]
}
]
}