# 8fold-marked 中文文档

规范地址：https://npmcn.com/package/8fold-marked/

版本：0\.3\.9
npm 元数据更新时间：2022-04-04T10:24:51.020Z
中文译文更新时间：2026-11-06T15:22:29.725Z
软件包许可：MIT

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/8fold-marked
原文对照：https://npmcn.com/package/8fold-marked/?lang=original
项目主页：https://github.com/8fold/marked
源码仓库：https://github.com/8fold/marked

弃用说明：Marked is active again: https://github\.com/markedjs/marked

## 关键信息（来自 npm 元数据）

- 模块格式：CommonJS
- TypeScript 类型：未声明
- 运行依赖：0 个
- 首次发布：2017-09-22T14:30:19.576Z
- 最新版本发布：2017-11-28T16:05:27.939Z
- 近 30 天下载量：2921（2026-10-04 至 2026-11-02，npm 官方下载统计）
- 已发布版本数：3（近 12 个月 0 个）

## 中文简介

为速度所建的标记下分解器

## 安装

```sh
npm install 8fold-marked
```

也可以使用：`pnpm add 8fold-marked`、`yarn add 8fold-marked`、`bun add 8fold-marked`

## README

_这叉子是迫不得已的 清楚的是,8倍并没有试图劫持主要项目._

_如果主要项目看来又恢复了,那么我们很可能会让它回到有能力的人手中。 与此同时,这个项目是来 [标记](https://github.com/chjj/marked) 希望主要项目的人没事。 所有PR都应该提交到这个 repo 这样我们就可以进行合并 `master` 并提交到主要项目._

# 标记

> 一个全地标下分解和编译器,用JavaScript来写. 已建成 为了速度.

[![NPM version](https://badge.fury.io/js/marked.png)](http://badge.fury.io/js/marked)

## 安装

```bash
npm install marked --save
```

## 使用量

最小使用量 :

```js
var marked = require('marked');
console.log(marked('I am using __markdown__.'));
// Outputs: <p>I am using <strong>markdown</strong>.</p>
```

带有默认值的选项设置示例 :

```js
var marked = require('marked');
marked.setOptions({
  renderer: new marked.Renderer(),
  gfm: true,
  tables: true,
  breaks: false,
  pedantic: false,
  sanitize: false,
  smartLists: true,
  smartypants: false,
  xhtml: false,
  baseUrl: null
});

console.log(marked('I am using __markdown__.'));
```

### 浏览器

```html
<!doctype html>
<html>
<head>
  <meta charset="utf-8"/>
  <title>Marked in the browser</title>
  <script src="lib/marked.js"></script>
</head>
<body>
  <div id="content"></div>
  <script>
    document.getElementById('content').innerHTML =
      marked('# Marked in browser\n\nRendered by **marked**.');
  </script>
</body>
</html>
```

## 标记( 标记下排 \[, 选项 \[, 回调\] )

### 标记下行

类型 : `string`

要编译的标记下源字符串 .

### 选项

类型 : `object`

一团糟 也可以使用 `marked.setOptions` 所用方法 见上文.

### 回调

类型 : `function`

函数在 `markdownString` 在使用时已全部解析 同步突出显示 。 如果 `options` 参数被省略,可用作 第二个论点.

## 选项

### 突出显示

类型 : `function`

一个突出代码块的函数. 下面的第一个实例是使用 async 突出显示 [节点- 平分- 捆绑](https://github.com/rvagg/node-pygmentize-bundled),第二个是使用 [突出显示.js](https://github.com/isagalaev/highlight.js)数字 :

```js
var marked = require('marked');

var markdownString = '```js\n console.log("hello"); \n```';

// Async highlighting with pygmentize-bundled
marked.setOptions({
  highlight: function (code, lang, callback) {
    require('pygmentize-bundled')({ lang: lang, format: 'html' }, code, function (err, result) {
      callback(err, result.toString());
    });
  }
});

// Using async version of marked
marked(markdownString, function (err, content) {
  if (err) throw err;
  console.log(content);
});

// Synchronous highlighting with highlight.js
marked.setOptions({
  highlight: function (code) {
    return require('highlight.js').highlightAuto(code).value;
  }
});

console.log(marked(markdownString));
```

#### 突出显示参数

`code`

类型 : `string`

要传递到亮点的代码部分 .

`lang`

类型 : `string`

代码块中指定的编程语言.

`callback`

类型 : `function`

使用 Aync 突出显示器时的调用函数 .

### 渲染器

类型 : `object` 默认 : `new Renderer()`

包含函数以向 HTML 渲染令牌的对象.

#### 覆盖式渲染器方法

渲染器选项允许您以自定义的方式制作令牌 。 这里有一个 通过在 GitHub 上添加嵌入式锚标记来压倒默认标题符号渲染的例子 :

```javascript
var marked = require('marked');
var renderer = new marked.Renderer();

renderer.heading = function (text, level) {
  var escapedText = text.toLowerCase().replace(/[^\w]+/g, '-');

  return '<h' + level + '><a name="' +
                escapedText +
                 '" class="anchor" href="#' +
                 escapedText +
                 '"><span class="header-link"></span></a>' +
                  text + '</h' + level + '>';
},

console.log(marked('# heading+', { renderer: renderer }));
```

此代码将输出以下 HTML :

```html
<h1>
  <a name="heading-" class="anchor" href="#heading-">
    <span class="header-link"></span>
  </a>
  heading+
</h1>
```

#### 块级渲染器方法

-   代码( c)_字符串_ 代码, _字符串_ 语言)
-   块引用( c)_字符串_ 引用)
-   html (中文(简体) )_字符串_ (中文(简体) )
-   标题( c)_字符串_ 文本,则, _编号_ 职等)
-   小时( )
-   列表( c)_字符串_ 躯体, _布尔_ 命令)
-   清单项目(e)_字符串_ 文本)
-   段 次 页 次_字符串_ 文本)
-   表格( 图表)_字符串_ 标题, _字符串_ 机构)
-   平面图( t)_字符串_ 内容)
-   表格单元格( t)_字符串_ 内容, _对象_ 旗帜)

`flags` 具有下列属性:

```js
{
    header: true || false,
    align: 'center' || 'left' || 'right'
}
```

#### 内置水平渲染器方法

-   强( r)_字符串_ 文本)
-   em( 时间)_字符串_ 文本)
-   代码( c)_字符串_ 代码)
-   br () (中文(简体) )
-   德尔( d)_字符串_ 文本)
-   链接( c)_字符串_ 赫尔夫, _字符串_ 标题, _字符串_ 文本)
-   图像( i)_字符串_ 赫尔夫, _字符串_ 标题, _字符串_ 文本)

### 小时

类型 : `boolean` 默认 : `true`

启用 [GitHub 有口味的标记](https://help.github.com/articles/github-flavored-markdown)。 。 。 .

### 图表

类型 : `boolean` 默认 : `true`

启用 GFM [图表](https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet#wiki-tables)。 。 。 . 此选项要求 `gfm` 选项为真实.

### 间断

类型 : `boolean` 默认 : `false`

启用 GFM [换行符](https://help.github.com/articles/github-flavored-markdown#newlines)。 。 。 . 此选项要求 `gfm` 选项为真实.

### 恋童癖

类型 : `boolean` 默认 : `false`

协调以模糊部分 `markdown.pl` 尽可能多 什么都别修 原始的标记下错误或不良行为.

### 净化

类型 : `boolean` 默认 : `false`

使输出达到无害化. 忽略任何输入的 HTML .

### 智能游戏

类型 : `boolean` 默认 : `true`

使用比最初的平分更聪明的列表行为. 最终可能 默认与旧行为移入 `pedantic`。 。 。 .

### 聪明人

类型 : `boolean` 默认 : `false`

使用"智能"的打字口号来表示引用和破折号等内容.

### ưμ㼯a

类型 : `boolean` 默认 : `false`

按XHTML的要求用"/"来自关闭空出元素(<br/>,<img/>等)的标记.

### 基数Url

类型 : `string` 默认: 无效

将相对链接和图像 URL 替换为针对指定碱基解决的值.

## 访问 Lexer 和 解析器

如果您愿意,您也可以直接访问该词汇和解析器.

```js
var tokens = marked.lexer(text, options);
console.log(marked.parser(tokens));
```

```js
var lexer = new marked.Lexer(options);
var tokens = lexer.lex(text);
console.log(tokens);
console.log(lexer.rules);
```

## 国 际

```bash
$ marked -o hello.html
hello world
^D
$ cat hello.html
<p>hello world</p>
```

## 标志背后的哲学

标记的要点是创建一个可进行标记的编译器 经常解开大块的打分 不用担心 隐藏编译的输出... 或屏蔽一段时间 无可否认地.

标记非常简洁,仍然执行所有降标特性。 这也是 现在与客户端完全兼容.

或多或少通过正式的减记测试套件 整个。 这一点很重要,因为惊人的下调编译器 只能通过几次测试。 很难被标记为 顺其自然 本来可以割出几地角 ,但并不是为了 准确的是你期望的 记分倒计时 事实上,这就是为什么可以在 以上基准中的不利因素.

在实施每个减记功能的同时,也进行标记 [全球调频 特性](http://github.github.com/github-flavored-markdown/)。 。 。 .

## 基准

节点 v0.8.x

```bash
$ node test --bench
marked completed in 3411ms.
marked (gfm) completed in 3727ms.
marked (pedantic) completed in 3201ms.
robotskirt completed in 808ms.
showdown (reuse converter) completed in 11954ms.
showdown (new converter) completed in 17774ms.
markdown-js completed in 17191ms.
```

**现在的标记速度快于"折扣",它用C来写.**

对于那些怀疑的人: 这些基准运行了整个减值测试套房1000次. 测试套房测试每个功能. 它不适应特定的方面.

### Pro 级别

如果您愿意,您也可以直接访问该词汇和解析器.

```js
var tokens = marked.lexer(text, options);
console.log(marked.parser(tokens));
```

```js
var lexer = new marked.Lexer(options);
var tokens = lexer.lex(text);
console.log(tokens);
console.log(lexer.rules);
```

```bash
$ node
> require('marked').lexer('> i am using marked.')
[ { type: 'blockquote_start' },
  { type: 'paragraph',
    text: 'i am using marked.' },
  { type: 'blockquote_end' },
  links: {} ]
```

## 运行测试和贡献( A)

如果你想提交拉动请求,请确保您的更改通过测试 套间。 如果新增了功能,请务必加入自己的测试.

标志性测试套房的设置有些奇怪: `test/new` 用于所有测试 不在原 markdown.pl 测试套件中(这里是您的 测试应该去 如果你做了一个. `test/original` 仅用于原件 {\\fn黑体\\fs22\\bord1\\shad0\\3ahbe\\4ah00\\fscx67\\fscy66\\2chffffff\\3ch808080}马克下... `test/tests` 两种测试都经过了 通过运行合并和移动/生成 `node test --fix` 或者说 `marked --test --fix`。 。 。 .

换句话说,如果你有测试要添加,就添加到 `test/new/` 接下来 使用 `node test --fix`提交结果。 如果你的测试 使用某种特性,例如,也许它假设GFM是 _没有_ 启用, 您 可添加 `.nogfm` 转到文件名。 这么说吧, `my-test.text` 变成 `my-test.nogfm.text`。你可以用任何标记的选项做到这一点。 说你想 已启用换行符和智能裤, 您的文件名应为: `my-test.breaks.smartypants.text`。 。 。 .

为了进行测试:

```bash
cd marked/
node test
```

### 捐款和许可证协定

如果您为此工程提供代码, 您将默认允许您的代码 根据麻省理工学院的许可证发放。 你也在暗中证实 所有代码都是你的原作. `</legalese>`

## 许可证

版权 (c)2011-2014, Christopher Jeffrey. (麻省理工学院许可证)

更多信息见LICENSE.

## 常见问题

### 8fold-marked 是什么？

为速度所建的标记下分解器注意：该包已被作者标记为弃用——Marked is active again: https://github\.com/markedjs/marked

### 如何安装 8fold-marked？

在项目目录运行 npm install 8fold-marked，或使用 pnpm add / yarn add / bun add。它还提供命令行工具 8fold-marked，可以用 npx 8fold-marked 直接运行。

### 8fold-marked 支持 TypeScript 吗？

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

### 8fold-marked 支持 ESM 还是 CommonJS？

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

### 8fold-marked 可以商用吗？

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

### 8fold-marked 的下载量有多少？

根据 npm 官方下载统计，8fold-marked 在 2026/10/04 – 2026/11/02 这 30 天内被下载 2,921 次，日均约 97 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入，适合横向比较热度，不能直接等同于使用人数。

### 8fold-marked 还在维护吗？

最新版本 0\.3\.9 发布于 2017/11/29（8 年前）；至今共发布 3 个版本，其中过去 12 个月发布了 0 个；首次发布于 2017/09/22。作者已将其标记为弃用，新项目建议寻找替代方案。

