markdown-it 版本是11.0.0 没有’target,_blank’属性,默认打开a标签的链接是本页面,会丢失之前的页面数据,需要在浏览器中新建页面打开,添加以下代码即可解决。
// Remember old renderer, if overridden, or proxy to default renderer
var md=require('markdown-it')
var defaultRender = md.renderer.rules.link_open || function(tokens, idx, options, env, self) {
return self.renderToken(tokens, idx, options);
};
md.renderer.rules.link_open = function (tokens, idx, options, env, self) {
// If you are sure other plugins can't add `target` - drop check below
var aIndex = tokens[idx].attrIndex('target');
if (aIndex < 0) {
tokens[idx].attrPush(['target', '_blank']); // add new attribute
} else {
tokens[idx].attrs[aIndex][1] = '_blank'; // replace value of existing attr
}
// pass token to default renderer.
return defaultRender(tokens, idx, options, env, self);
};