import {highlight, languages} from 'prismjs'; import PrismLoader from 'prismjs/components/index'; import stripIndent from 'strip-indent'; import {liquidEngine} from '../engines'; import {default as codeExample} from './codeExample'; import {compatibility, implStatus} from './compatibility'; import {getDocTocData, getToc} from './toc'; export {codeExample}; export {compatibility, implStatus}; export {getDocTocData, getToc}; /** * Returns HTML for a fun fact that's not directly relevant to the main * documentation. */ export const funFact = async (contents: string, useMarkdown = true) => { const html = await liquidEngine.renderFile('fun_fact', { // Un-indent nested markup to prevent unwanted `
` tags. contents: stripIndent(contents).replaceAll(/\n + { const html = await liquidEngine.renderFile('heads_up', { // Un-indent nested markup to prevent unwanted `
` tags. contents: stripIndent(contents).replaceAll(/\n + { if (!languages[language]) { PrismLoader(language); } const code = `${contents}${'\n'.repeat(padding + 1)}`; const html = highlight(code, languages[language], language); const attr = `language-${language}`; return `
${html.replaceAll(
'\n',
'
'
)}
`;
};
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export default function componentsPlugin(eleventyConfig: any) {
// filters...
eleventyConfig.addLiquidFilter('implStatus', implStatus);
eleventyConfig.addLiquidFilter('getDocTocData', getDocTocData);
eleventyConfig.addLiquidFilter('getToc', getToc);
// paired shortcodes...
eleventyConfig.addPairedLiquidShortcode('code', codeBlock);
eleventyConfig.addPairedLiquidShortcode('codeExample', codeExample);
// Ideally this could be used with named args, but that's not supported yet in
// 11ty's implementation of LiquidJS:
// https://github.com/11ty/eleventy/issues/2679
// In the meantime, check the order in the function definition of
// `compatibility` in `source/helpers/components/compatibility.ts`.
eleventyConfig.addPairedLiquidShortcode('compatibility', compatibility);
eleventyConfig.addPairedLiquidShortcode('funFact', funFact);
eleventyConfig.addPairedLiquidShortcode('headsUp', headsUp);
}