mirror of
https://github.com/youzan/vant.git
synced 2025-10-20 18:54:24 +00:00
docs: add target blank for all links (#5073)
This commit is contained in:
18
packages/vant-markdown-loader/src/link-open.js
Normal file
18
packages/vant-markdown-loader/src/link-open.js
Normal file
@@ -0,0 +1,18 @@
|
||||
// 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);
|
||||
};
|
||||
};
|
Reference in New Issue
Block a user