Wondering what’s next for npm?Check out our public roadmap! »

    @contentful/rich-text-from-markdown

    14.1.2 • Public • Published

    rich-text-from-markdown

    A library to convert markdown to Contentful Rich Text document format.

    Installation

    Using npm:

    npm install @contentful/rich-text-from-markdown

    Using yarn:

    yarn add @contentful/rich-text-from-markdown

    Usage

    Basic

    const { richTextFromMarkdown } = require('@contentful/rich-text-from-markdown');
     
    const document = await richTextFromMarkdown('# Hello World');

    Advanced

    The library will convert automatically the following markdown nodes:

    • paragraph
    • heading
    • text
    • emphasis
    • strong
    • delete
    • inlineCode
    • link
    • thematicBreak
    • blockquote
    • list
    • listItem

    If the markdown content has unsupported nodes like image ![image](url) you can add a callback as a second argument and it will get called everytime an unsupported node is found. The return value of the callback will be the rich text representation of that node.

    Example:

    const { richTextFromMarkdown } = require('@contentful/rich-text-from-markdown');
     
    // define your own type for unsupported nodes like asset
    const document = await richTextFromMarkdown(
      '![image](\'https://example.com/image.jpg\')',
      node => ({
        nodeType: 'embedded-[entry|asset]-[block|inline]',
        content: [],
        data: {
          target: {
            sys: {
              type: 'Link',
              linkType: 'Entry|Asset',
              id: '.........'
            }
          }
        }
      })
    );

    Install

    npm i @contentful/rich-text-from-markdown

    DownloadsWeekly Downloads

    6,186

    Version

    14.1.2

    License

    MIT

    Unpacked Size

    2.09 MB

    Total Files

    23

    Last publish

    Collaborators

    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar