富文本自标记
一个将缩放转换为 Contentful Rich Text 文档格式的库 .
安装
使用 无数字 :
npm install @contentful/rich-text-from-markdown
使用 线条数字 :
yarn add @contentful/rich-text-from-markdown
使用量
基础
const { richTextFromMarkdown } = require('@contentful/rich-text-from-markdown');
const document = await richTextFromMarkdown('# Hello World');
高级
库会自动转换以下标记下节点:
paragraphheadingtextemphasisstrongdeleteinlineCodelinkthematicBreakblockquotelistlistItemtabletableRowtableCell
如果标记下的内容有像图像这样的不支持的节点  您可以添加回调作为第二个参数
每次找到一个不支持的节点 都会叫它 回调的回调值将是丰富的文本代表
那个节点.
示例
const { richTextFromMarkdown } = require('@contentful/rich-text-from-markdown');
// define your own type for unsupported nodes like asset
const document = await richTextFromMarkdown(
"",
(node) => ({
nodeType: 'embedded-[entry|asset]-[block|inline]',
content: [],
data: {
target: {
sys: {
type: 'Link',
linkType: 'Entry|Asset',
id: '.........',
},
},
},
}),
);