1.0.3 • Published 10 months ago

miguel-rich-text-markdown-renderer v1.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

rich-text-markdown-renderer

A library to convert Contentful Rich Text Document to Markdown in Github Markdown Format (gmf).

Installation

Using npm:

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

Using yarn:

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

Features

  • Support for ordered lists 🔢
  • Extend default behavior with custom renderers 🔧

Usage

Basic

import { documentToMarkdown } from '@contentful/rich-text-markdown-renderer';

const document = {
  nodeType: 'document',
  data: {},
  content: [
    {
      nodeType: 'paragraph',
      data: {},
      content: [
        {
          nodeType: 'text',
          value: 'Hello',
          marks: [{ type: 'bold' }],
          data: {},
        },
        {
          nodeType: 'text',
          value: ' world!',
          marks: [{ type: 'italic' }],
          data: {},
        },
      ],
    },
  ],
};

documentToMarkdown(document)); // -> Hello world!

Advanced

documentToMarkdown(document, {
  renderNode: {
    [BLOCKS.EMBEDDED_ASSET]: (node) => {
      return `![${node.data.target.fields.title}](${node.data.target.fields.file.url})\n`;
    },
  },
});
1.0.3

10 months ago

1.0.2

10 months ago

1.0.1

10 months ago

1.0.0

10 months ago