将Markdown文本转为Html代码
## 简介 现在有很多流行的Markdown编辑器,但有时需要的不是一个庞大的编辑器,而是一个可以将
渲染中...
## 简介
现在有很多流行的Markdown编辑器,但有时需要的不是一个庞大的编辑器,而是一个可以将Markdown文本格式化为Html代码的工具,所以找到了:**Markedjs**
- Github地址:https://github.com/markedjs/marked
- 官网:https://marked.js.org/
<!-- more -->
## 官方使用示例
### Installation(安装)
**CLI:**
```bash
npm install -g marked
```
**In-browser:**
```bash
npm install marked
npm install @types/marked # For TypeScript projects
```
### Usage(使用)
** Warning: 🚨 Marked does not [sanitize](https://marked.js.org/#/USING_ADVANCED.md#options) the output HTML. Please use a sanitize library, like [DOMPurify](https://github.com/cure53/DOMPurify) (recommended), [sanitize-html](https://github.com/apostrophecms/sanitize-html) or [insane](https://github.com/bevacqua/insane) on the *output* HTML! 🚨 **
```
DOMPurify.sanitize(marked.parse(`<img src="x" onerror="alert('not happening')">`));
```
#### CLI
```bash
# Example with stdin input
$ marked -o hello.html
hello world
^D
$ cat hello.html
<p>hello world</p>
```
```bash
# Print all options
$ marked --help
```
#### Browser
> 通过`marked.parse()`方法格式化Markdown文本。
```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/marked.min.js"></script>
<script>
document.getElementById('content').innerHTML =
marked.parse('# Marked in the browser\n\nRendered by **marked**.');
</script>
</body>
</html>
``` END
评论
登录后查看和发表评论
前往登录