import { execSync } from 'node:child_process'; const html = (strings, ...values) => String.raw({ raw: strings }, ...values); function htmlEscape(s) { const lookup = { '&': "&", '"': """, '\'': "'", '<': "<", '>': ">" }; return s.replace( /[&"'<>]/g, c => lookup[c] ); } /** @param {import('@11ty/eleventy').UserConfig} eleventyConfig */ export function setupShortcodes(eleventyConfig) { eleventyConfig.addPairedShortcode('code', (code, lang, filename) => { let highlighted; if (lang != null && lang !== "" && lang !== "plain") { highlighted = execSync(`arborium --html --lang ${lang}`, { input: code.trim(), encoding: 'utf-8', }) } const caption = lang || filename ? html`
${lang ? html`${lang}` : ''} ${filename ? html`${filename}` : ''}
` : '' return html`
${caption}
${highlighted ?? htmlEscape(code.trim())}
` }) eleventyConfig.addPairedShortcode('speech', (contents, option) => { return html` ` }) }