@contentful/rich-text-from-markdown

中文文档
16.2.2发布于 2026/07/21MITTypeScriptESM + CJS近 30 天下载 41.2万

convert markdown to rich text

原始使用文档
文档目录4 节
  1. Installation
  2. Usage
  3. Basic
  4. Advanced

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

版本与发布记录

@contentful/rich-text-from-markdown 共发布 90 个版本,首次发布于 2018/11/08;过去 12 个月发布了 3 个版本。

版本发布日期距今
16.2.2latest2026/07/213 个月前
16.2.12026/04/097 个月前
16.2.02026/04/087 个月前
16.1.82025/11/041 年前
16.1.72025/09/231.1 年前
16.1.62025/09/231.1 年前

关于 @contentful/rich-text-from-markdown 的常见问题

@contentful/rich-text-from-markdown 是什么?

convert markdown to rich text

如何安装 @contentful/rich-text-from-markdown?

在项目目录运行 npm install @contentful/rich-text-from-markdown,或使用 pnpm add / yarn add / bun add。

@contentful/rich-text-from-markdown 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@contentful/rich-text-from-markdown 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@contentful/rich-text-from-markdown 可以商用吗?

@contentful/rich-text-from-markdown 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@contentful/rich-text-from-markdown 的下载量有多少?

根据 npm 官方下载统计,@contentful/rich-text-from-markdown 在 2026/10/11 – 2026/11/09 这 30 天内被下载 411,621 次,日均约 13,721 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@contentful/rich-text-from-markdown 还在维护吗?

最新版本 16.2.2 发布于 2026/07/21(3 个月前);至今共发布 90 个版本,其中过去 12 个月发布了 3 个;首次发布于 2018/11/08。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。