查看演示页面 了解 Marked 的实际效果⛹️
我们的文档页面 也使用 marked 💯 渲染。
另请参阅:
Node.js: 仅支持当前版本和 LTS 版本。已停产的 Node.js 版本可能随时与 Marked 不兼容。
浏览器: 非 IE11 :)
命令行:
npm install -g marked
浏览器内:
npm install marked
警告:🚨 Marked 不会对输出的 HTML 进行 清理。请使用清理库对输出的 HTML 进行清理,例如 DOMPurify(推荐)、sanitize-html 或 insane! 🚨
DOMPurify.sanitize(marked.parse(`<img src="x" onerror="alert('未发生')">`));
命令行界面
# 使用标准输入的示例
$ marked -o hello.html
hello world
^D
$ cat hello.html
<p>hello world</p>
# 打印所有选项
$ marked --help
浏览器
<!doctype html>
<html>
<head>
<meta charset="utf-8"/>
<title>浏览器中的 Marked</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\n\n由 **marked** 渲染。');
</script>
</body>
</html>
或导入 esm 模块
<script type="module">
从 "https://cdn.jsdelivr.net/npm/marked/lib/marked.esm.js" 导入 { marked };
document.getElementById('content').innerHTML =
marked.parse('# Marked 在浏览器中\n\n由 **marked** 渲染。');
</script>
版权所有 (c) 2011-2022,Christopher Jeffrey。(MIT 许可证)