miguel-rich-text-markdown-renderer
v1.0.3
Published
A library to convert Contentful Rich Text Document to Markdown in [Github Markdown Format (gmf)](https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax).
Downloads
10
Readme
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`;
},
},
});