@edwinjoseph/prismic-richtext-markdown

中文文档
1.2.5发布于 2020/09/09MITCommonJS近 30 天下载 4248

A method that converts Prismic's rich text blob into a markdown string.

原始使用文档
文档目录5 节
  1. Supported options
  2. Confirmed markdown packages that work with this
  3. Usage
  4. Example Prismic document
  5. Handling rich text

Prismic RichText Markdown

GitHub Workflow Status npm

NOTE: This package only supports Prismic API V2, you may use this if you are using V1 but will need to remap the richtext blob being passed in. Although this is not advised.

This is a method that converts the data that comes from Prismic's RichText field into a markdown string.

Supported options

  • Heading 1-6
  • Bold
  • Italics
  • Images
  • Link to web
  • Link to media
  • Link to document
  • Ordered lists
  • Unordered lists
  • Preformated
  • Embedded
  • Right to left

Confirmed markdown packages that work with this

It is most likely that this method works with most markdown packages, however I have only tested this with:

Usage

Example Prismic document

{
  "id": "WKxlPCUEEIZ10AHU",
  "uid": "example-page",
  "type": "page",
  "href": "https://your-repo-name.prismic.io/api/documents/search...",
  "tags": [],
  "first_publication_date": "2017-01-13T11:45:21.000Z",
  "last_publication_date": "2017-02-21T16:05:19.000Z",
  "slugs": [
    "example-page"
  ],
  "linked_documents": [],
  "lang": "en-us",
  "alternate_languages": [...],
  "data": {
    "title": [
      {
        "type": "heading1",
        "text": "Example Page",
        "spans": []
      }
    ]
  }
}

Handling rich text

import MarkdownIt from 'markdown-it';
import richTextToMarkdown from '@edwinjoseph/prismic-richtext-markdown';

// resolver function example from https://prismic.io/docs/javascript/beyond-the-api/link-resolving
const linkResolver = (doc) => {
  // Pretty URLs for known types
  if (doc.type === 'blog') return "/post/" + doc.uid;
  if (doc.type === 'page') return "/" + doc.uid;
  // Fallback for other types, in case new custom types get created
  return "/doc/" + doc.id;
};

const md = new MarkdownIt();

const mkdown = richTextToMarkdown(document.data.title, linkResolver);
const result = md.render(mkdown);
// => <h1>Example Page</h1>

版本与发布记录

@edwinjoseph/prismic-richtext-markdown 共发布 8 个版本,首次发布于 2020/09/09;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.2.5latest2020/09/096 年前
1.2.42020/09/096 年前
1.2.32020/09/096 年前
1.2.22020/09/096 年前
1.2.12020/09/096 年前
1.2.02020/09/096 年前

关于 @edwinjoseph/prismic-richtext-markdown 的常见问题

@edwinjoseph/prismic-richtext-markdown 是什么?

A method that converts Prismic's rich text blob into a markdown string.

如何安装 @edwinjoseph/prismic-richtext-markdown?

在项目目录运行 npm install @edwinjoseph/prismic-richtext-markdown,或使用 pnpm add / yarn add / bun add。

@edwinjoseph/prismic-richtext-markdown 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/edwinjoseph__prismic-richtext-markdown 是否存在。

@edwinjoseph/prismic-richtext-markdown 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@edwinjoseph/prismic-richtext-markdown 可以商用吗?

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

@edwinjoseph/prismic-richtext-markdown 的下载量有多少?

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

@edwinjoseph/prismic-richtext-markdown 还在维护吗?

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