11ty-plugin-giallo/.eleventy.js

29 lines
922 B
JavaScript
Raw Normal View History

2026-01-23 19:30:29 +00:00
import pkg from "./package.json" with { type: "json" };
import markdownHighlighter from "./src/giallo-markdown.js";
/**
* Giallo syntax highlighting plugin for Eleventy. Logic distilled from
* https://github.com/11ty/eleventy-plugin-syntaxhighlight. Currently supports
* markdown blocks only.
*/
export default function (eleventyConfig, options) {
try {
eleventyConfig.versionCheck(pkg["11ty"].compatibility);
} catch (e) {
console.log(
`WARN: Eleventy Plugin (${pkg.name}) Compatibility: ${e.message}`,
);
}
if (hasTemplateFormat(options.templateFormats, "md")) {
eleventyConfig.addMarkdownHighlighter(markdownHighlighter(options));
}
}
function hasTemplateFormat(templateFormats = ["*"], format = false) {
const formatsArr = Array.isArray(templateFormats)
? templateFormats
: [templateFormats];
return formatsArr.indexOf("*") > -1 || formatsArr.indexOf(format) > -1;
}