mirror of
https://github.com/tcsenpai/obsidiangarden_netlify.git
synced 2025-06-06 20:55:21 +00:00
Add target and class to external links
This commit is contained in:
parent
ebb4746426
commit
9241b5431f
23
.eleventy.js
23
.eleventy.js
@ -26,6 +26,29 @@ module.exports = function(eleventyConfig) {
|
||||
// Other languages
|
||||
return origRule(tokens, idx, options, env, slf);
|
||||
};
|
||||
|
||||
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');
|
||||
const classIndex = tokens[idx].attrIndex('class');
|
||||
|
||||
if (aIndex < 0) {
|
||||
tokens[idx].attrPush(['target', '_blank']);
|
||||
} else {
|
||||
tokens[idx].attrs[aIndex][1] = '_blank';
|
||||
}
|
||||
|
||||
if (classIndex< 0) {
|
||||
tokens[idx].attrPush(['class', 'external-link']);
|
||||
} else {
|
||||
tokens[idx].attrs[classIndex][1] = 'external-link';
|
||||
}
|
||||
|
||||
return defaultRender(tokens, idx, options, env, self);
|
||||
};
|
||||
});
|
||||
|
||||
eleventyConfig.setLibrary("md", markdownLib);
|
||||
|
Loading…
x
Reference in New Issue
Block a user