add markdown rendering for program

This commit is contained in:
Lyn Fugmann 2024-09-27 16:32:04 +02:00
parent e376bc1389
commit 49f39f1ecb
6 changed files with 126 additions and 25 deletions

View file

@ -73,6 +73,30 @@ module.exports = function(eleventyConfig) {
return value.filter(item => item.page.lang === this.page.lang)
});
eleventyConfig.addAsyncFilter('mdInline', async function(value) {
// TODO replace with ESM import once we switch to Eleventy v3
const md = (await import('markdown-it/index.mjs')).default();
// customize link rendering
md.renderer.rules.link_open = function (tokens, idx, options, env, self) {
const href = tokens[idx].attrGet('href');
if (href.startsWith('http')) {
tokens[idx].attrSet('target', '_blank');
tokens[idx].attrSet('rel', 'noreferrer');
} else {
const newHref = eleventyConfig.javascriptFunctions.locale_url(href);
tokens[idx].attrSet('href', newHref);
}
tokens[idx].attrSet('class', 'link');
return self.renderToken(tokens, idx, options);
};
return md.renderInline(value);
});
// copy aileron font
eleventyConfig.addPassthroughCopy({'./submodules/aileron/fonts/*.(ttf|woff|woff2)': 'fonts'})
eleventyConfig.addPassthroughCopy({'./submodules/aileron/aileron.lite.min.css': 'aileron.lite.min.css'})