lightning-talk-css/config/plugins/markdown.js
2023-09-29 19:33:03 +01:00

52 lines
1.3 KiB
JavaScript

const path = require("path");
const markdownIt = require('markdown-it');
const markdownItPrism = require('markdown-it-prism');
const markdownItClass = require('@toycode/markdown-it-class');
const markdownItLinkAttributes = require('markdown-it-link-attributes');
const markdownItEmoji = require('markdown-it-emoji');
const markdownItFootnote = require('markdown-it-footnote');
const markdownitMark = require('markdown-it-mark');
const markdownitAbbr = require('markdown-it-abbr');
const icons = require('./icons.json');
const { slugifyString } = require('../utils');
const markdownLib = markdownIt({
html: true,
breaks: true,
linkify: true,
typographer: true
})
.disable('code')
.use(markdownItPrism, {
defaultLanguage: 'plaintext'
})
.use(markdownItClass, {
ol: 'list',
ul: 'list'
})
.use(markdownItLinkAttributes, [
{
// match external links
matcher(href) {
return href.match(/^https?:\/\//);
},
attrs: {
target: '_blank',
rel: 'noreferrer noopener'
}
}
])
.use(markdownItEmoji, { defs: icons })
.use(markdownItFootnote)
.use(markdownitMark)
.use(markdownitAbbr);
markdownLib.renderer.rules.emoji = function(token, idx) {
return `<span class="fa-li"><i class="fa-solid fa-${token[idx].markup}"></i></span>`;
};
module.exports = function(eleventyConfig) {
eleventyConfig.setLibrary('md', markdownLib);
};