js: markdown-it: Markdown解析器 文档: github: https://github.com/markdown-it/markdown-it github: https://github.com/markdown-it/markdown-it-for-inline doc: ...
js: markdown-it: Markdown解析器
文档:
github: <a href="https://github.com/markdown-it/markdown-it">https://github.com/markdown-it/markdown-it</a> github: <a href="https://github.com/markdown-it/markdown-it-for-inline">https://github.com/markdown-it/markdown-it-for-inline</a> doc: <a href="https://github.com/markdown-it/markdown-it/blob/master/docs/architecture.md#renderer">https://github.com/markdown-it/markdown-it/blob/master/docs/architecture.md#renderer</a>
npm i -S markdown-it markdown-it-for-inline
1、默认default
linkify: false
var md = require("markdown-it")()
const text = "http://www.baidu.com";
var result = md.render(text);
console.log(result);
输出
<p>http://www.baidu.com</p>
2、自动识别url
linkify: true
var md = require("markdown-it")({ linkify: true })
const text = "http://www.baidu.com";
var result = md.render(text);
console.log(result);
输出
<p><a href="http://www.baidu.com">http://www.baidu.com</a></p>
3、自动识别url 并设置新窗口打开
linkify: true && target=_blank
var iterator = require("markdown-it-for-inline");
var md = require("markdown-it")({ linkify: true }).use(
iterator,
"url_new_win",
"link_open",
function(tokens, idx) {
var aIndex = tokens[idx].attrIndex("target");
if (aIndex < 0) {
tokens[idx].attrPush(["target", "_blank"]);
} else {
tokens[idx].attrs[aIndex][1] = "_blank";
}
}
);
const text = "http://www.baidu.com";
var result = md.render(text);
console.log(result);
输出
<p><a href="http://www.baidu.com" target="_blank">http://www.baidu.com</a></p>
本站为非盈利网站,如果您喜欢这篇文章,欢迎支持我们继续运营!
本站主要用于日常笔记的记录和生活日志。本站不保证所有内容信息可靠!(大多数文章属于搬运!)如有版权问题,请联系我立即删除:“abcdsjx@126.com”。
QQ: 1164453243
邮箱: abcdsjx@126.com