Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@contentful/rich-text-from-markdown

Package Overview
Dependencies
Maintainers
0
Versions
77
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@contentful/rich-text-from-markdown

convert markdown to rich text

  • 16.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
60K
increased by12.14%
Maintainers
0
Weekly downloads
 
Created
Source

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
  • table
  • tableRow
  • tableCell

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: '.........',
        },
      },
    },
  }),
);

Keywords

FAQs

Package last updated on 29 Oct 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc