Skip to content

Instantly share code, notes, and snippets.

@jaylandro
Last active April 30, 2020 05:08
Show Gist options
  • Save jaylandro/a16d4df00b2a60735bb9b9222244e180 to your computer and use it in GitHub Desktop.
Save jaylandro/a16d4df00b2a60735bb9b9222244e180 to your computer and use it in GitHub Desktop.
11ty: Convert href links to markdown (.md) files to directory path links
const markdownEngine = markdownIt({
html: true,
linkify: true
});
const defaultRender = markdownEngine.renderer.rules.link_open || function(tokens, idx, options, env, self) {
return self.renderToken(tokens, idx, options);
};
markdownEngine.renderer.rules.link_open = function (tokens, idx, options, env, self) {
const isMarkDownLink = tokens[idx].attrGet('href').search('.md') !== -1;
if (isMarkDownLink) {
let newLink = tokens[idx].attrGet('href').replace('.md', '');
tokens[idx].attrSet('href', newLink);
}
return defaultRender(tokens, idx, options, env, self);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment