29 lines
922 B
JavaScript
29 lines
922 B
JavaScript
|
|
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;
|
||
|
|
}
|