Vue配置marked链接添加target=\"_blank\"
1. 引入marked
package.json
"dependencies": { "marked": "^0.3.9" }
import marked from "marked";
2. 修改生成的HTML的方法
const renderer = new marked.Renderer(); //https://github.com/markedjs/marked/issues/655#issuecomment-383226346 const linkRenderer = renderer.link; renderer.link = (href, title, text) => { const html = linkRenderer.call(renderer, href, title, text); return html.replace(/^<a /, '<a target="_blank" rel="nofollow" '); }; const html = marked(markdown, { renderer });
Tips:marked参数配置
const renderer = new marked.Renderer(); //基本设置 marked.setOptions({ renderer: renderer, gfm: true, //允许 Git Hub标准的markdown. tables: true, //允许支持表格语法(该选项要求 gfm 为true) breaks: true, //允许回车换行(该选项要求 gfm 为true) pedantic: false, //不纠正原始模型任何的不良行为和错误(默认为false) sanitize: false, //对输出进行过滤(清理),将忽略任何已经输入的html代码(标签) smartLists: true, //使用比原生markdown更时髦的列表 smartypants: false //使用更为时髦的标点 });
相关推荐
EdwardSiCong 2020-11-23
yungpheng 2020-10-19
jipengx 2020-11-12
橄榄 2020-11-03
lyqdanang 2020-11-02
wservices 2020-10-30
onepiecedn 2020-10-29
数据人 2020-10-26
dfphoto 2020-10-16
hackerlpy 2020-09-07
tianyayi 2020-08-16
Dullonjiang 2020-08-15
fengling 2020-08-15
wordmhg 2020-08-06
guotiaotiao 2020-08-06
zhangsyi 2020-07-28
千锋 2020-07-27
ahnjwj 2020-07-28