storyblok-markdown-richtext
TypeScript icon, indicating that this package has built-in type declarations

1.0.3 • Public • Published

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'
        }
      ]
    }
  ]
}

Powered by Storyblok

/storyblok-markdown-richtext/

    Package Sidebar

    Install

    npm i storyblok-markdown-richtext

    Weekly Downloads

    2,249

    Version

    1.0.3

    License

    MIT

    Unpacked Size

    85.8 kB

    Total Files

    22

    Last publish

    Collaborators

    • christianzoppisb
    • jpcfreire
    • delooks
    • dominikangerer
    • emanuelgsouza
    • samuells