marked README

The project's README from github.com/markedjs/marked. As one markdown file: README.md.

Marked

npm install size downloads github actions snyk inspect.software

Demo

Check out the demo page to see Marked in action ⛹️

Docs

Our documentation pages are also rendered using marked 💯

Also read about:

Compatibility

Node.js: Only current and LTS Node.js versions are supported. End of life Node.js versions may become incompatible with Marked at any point in time.

Browser: Baseline Widely Available

Installation

CLI:

npm install -g marked

In-browser:

npm install marked

Usage

Warning: 🚨 Marked does not sanitize the output HTML. Please use a sanitize library, like DOMPurify (recommended), sanitize-html or insane on the output HTML! 🚨

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);

Browser

<!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>

or import esm module

<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>

License

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

marked (markedjs/marked)

Searching Database…

37.2K ·GitHub
这是什么?Marked 是一个以速度为目标的 markdown 解析和编译工具。你把 markdown 文本交给它,它返回 HTML,可以在浏览器、服务器或命令行中运行。
它是我在代码里调用的库,还是一个做好的应用?是一个可以在自己的代码里调用的 JavaScript 库,另外还带一个小型 CLI,可以直接在终端里转换 markdown。如果只是想粘贴 markdown 看看效果,还有一个演示页面可用。
我怎么把它加到项目里?从 npm 安装:全局安装用 CLI(npm install -g marked),或者作为项目依赖安装用于库场景;在浏览器里,通过 script 标签加载,或导入 ESM 模块。文档在 marked.js.org。
要让它跑起来,我需要装什么?在服务器或 CLI 上使用时,需要一个受支持的 Node.js:只支持当前版本和 LTS 版本,这个包面向 Node 20+。在浏览器里,任何 Baseline Widely Available 的浏览器都可以,而且这个库本身没有任何运行时依赖。
它生成的 HTML 能直接放进我的页面吗,安全吗?不行——Marked 不会对输出做净化处理。如果 markdown 内容可能来自用户,请先用 DOMPurify(推荐)、sanitize-html 或 insane 这类净化工具处理生成的 HTML。
它能在哪些地方运行?只要能运行 JavaScript 的地方都可以:现代浏览器(Baseline Widely Available)、服务器上的 Node.js,以及通过 CLI 在终端里运行。
它用什么许可证?MIT,所以在个人和商业项目中都可以免费使用。版权由 MarkedJS(2018 年起)和 Christopher Jeffrey(2011-2018 年)持有。
Marked 最大的卖点是什么?速度快、体积轻:它是一个底层编译器,解析 markdown 时不做缓存、也不会长时间阻塞,同时保持轻量,并完整实现了所支持的各种 markdown 规范和方言中的全部功能。
它支持 GFM 和 CommonMark 吗?它实现了所支持的各种 markdown 规范和方言中的全部功能,而且仓库的主题标签里明确列出了 commonmark 和 gfm 规范。
我能添加自定义语法或行为吗?可以。可扩展性是核心特性之一:Marked 很容易通过自定义扩展进行改造,文档里除了 Options 参考之外,还有专门的 Extensibility(扩展)章节。
安装之前有没有简单的方法先试试?有——README 里链接了一个演示页面,可以直接看到 Marked 的实际效果,而且文档网站本身就是用 Marked 渲染的。
Creator
markedjs
Size
10.7 MB
Stars
37.2K
Age
15y
Commits · 90 Days