mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
19 lines
541 B
JavaScript
19 lines
541 B
JavaScript
// add target="_blank" to all links
|
|
module.exports = function linkOpen(md) {
|
|
const 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) {
|
|
const aIndex = tokens[idx].attrIndex('target');
|
|
|
|
if (aIndex < 0) {
|
|
tokens[idx].attrPush(['target', '_blank']); // add new attribute
|
|
}
|
|
|
|
return defaultRender(tokens, idx, options, env, self);
|
|
};
|
|
};
|