02strich-markdown

中文文档
1.0.2发布于 2023/04/05MITCommonJS

ReadMe's React-based Markdown parser

原始使用文档
文档目录8 节
  1. Usage
  2. Export Methods
  3. Settings & Options
  4. Flavored Syntax
  5. Local Development
  6. Environment setup
  7. Running visual regression tests
  8. Credits

@readme/markdown

ReadMe's flavored Markdown parser and MDX rendering engine. RDMD CI Status

npm install --save @readme/markdown

Usage

By default, the updated markdown package exports a function which takes a string of ReadMe-flavored markdown and returns a tree of React components:

import React from 'react';
import rdmd from "@readme/markdown";

export default ({ body }) => (
  <div className="markdown-body">
    {rdmd(body)}
  </div>
);

Export Methods

In addition to the default React processor, the package exports some other methods for transforming ReadMe-flavored markdown:

ExportDescriptionArguments
react(default) returns a VDOM tree objecttext, options
mdtransform mdast in to ReadMe-flavored markdowntree, options
htmltransform markdown in to HTMLtext, options
mdasttransform markdown to an mdast objecttext, options
hasttransform markdown to HAST objecttext, options
plaintransform markdown to plain texttext, options
utilscontexts, defaults, helpers, etc.N/A

Settings & Options

Each processor method takes an options object which you can use to adjust the output HTML or React tree. These options include:

  • compatibilityMode — Enable compatibility features from our old markdown engine.
  • copyButtons — Automatically insert a button to copy a block of text to the clipboard. Currently used on <code> elements.
  • correctnewlines — Render new line delimeters as <br> tags.
  • markdownOptions — Remark parser options.
  • safeMode — Render html blocks as <pre> elements. We normally allow all manner of html attributes that could potentially execute JavaScript.

Flavored Syntax

Our old editor rendered "Magic Block" components from a custom, JSON-based syntax. To provide seamless backwards-compatibility, our new processor ships with built in support for parsing this old format, and transpiles it straight in to our new, flavored Markdown.

We've also sprinkled a bit of our own syntactic sugar on top to let you supercharge your docs. Learn more about ReadMe's flavored syntax!

Local Development

To make changes to the RDMD engine locally, run the local development server. Clone the repo, cd in to it, npm install, and npm run start!

Environment setup

Running the browser tests requires docker. Follow the docker install instructions for mac. You may want to increase the memory usage. If you have not already, you'll need to create an account for docker hub and sign-in locally.

Running visual regression tests

If you make changes to the docs or how the markdown is rendered, you may need to update the visual regression snapshots. You can run the visual regression tests in a docker container with:

make updateSnapshot

Credits

版本与发布记录

02strich-markdown 共发布 3 个版本,首次发布于 2023/03/22;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.0.2latest2023/04/053 年前
1.0.12023/03/223 年前
1.0.02023/03/223 年前

关于 02strich-markdown 的常见问题

02strich-markdown 是什么?

ReadMe的基于react的Markdown解析器

如何安装 02strich-markdown?

在项目目录运行 npm install 02strich-markdown,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@readme/variable(^15.1.0)、@tippyjs/react(^4.1.0)、react(^17.0.0)、react-dom(^17.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

02strich-markdown 支持 TypeScript 吗?

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

02strich-markdown 支持 ESM 还是 CommonJS?

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

02strich-markdown 可以商用吗?

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

02strich-markdown 还在维护吗?

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