ITADN
markedjs/marked
README.md
以下内容由 AI 翻译,如有问题请点此提交 issue 反馈

Marked

npm install size downloads github actions snyk

  • ⚡ 为速度而生
  • ⬇️ 用于解析 markdown 的底层编译器,无需缓存或长时间阻塞
  • ⚖️ 轻量级,同时实现了受支持的方言和规范中的所有 markdown 功能
  • 🌐 可在浏览器、服务器或命令行界面 (CLI) 中运行

Demo

查看 demo page 以查看 Marked 的实际效果 ⛹️

Docs

我们的 documentation pages 也是使用 marked 渲染的 💯

另请参阅:

Compatibility

Node.js: 仅支持 current and LTS Node.js 版本。已停止支持的 Node.js 版本可能随时与 Marked 不兼容。

Browser: Baseline Widely Available

Installation

CLI:

npm install -g marked

在浏览器中:

npm install marked

用法

警告:🚨 Marked 不会对输出 HTML 进行净化。请在输出 HTML 上使用净化库,例如 DOMPurify(推荐)、sanitize-htmlinsane!🚨

DOMPurify.sanitize(marked.parse(`<img src="x" onerror="alert('not happening')">`));

CLI

# Example with stdin input
$ marked -o hello.html
hello world
^D
$ cat hello.html
<p>hello world</p>
# Print all options
$ marked --help

Node.js

import { marked } from 'marked';
const html = marked.parse('# Marked in Node.js');
console.log(html);

浏览器

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

或导入 esm 模块

<script type="module">
  import { marked } from "https://cdn.jsdelivr.net/npm/marked/lib/marked.esm.js";
  document.getElementById('content').innerHTML =
    marked.parse('# Marked in the browser\n\nRendered by **marked**.');
</script>

许可证

Copyright (c) 2018+, MarkedJS. (MIT License) Copyright (c) 2011-2018, Christopher Jeffrey. (MIT License)