deno.land / x / lume@v2.1.4 / plugins / prism.ts
12345678910111213141516171819202122232425262728293031323334import Prism from "../deps/prism.ts";import { merge } from "../core/utils/object.ts";
import type Site from "../core/site.ts";import type { Page } from "../core/file.ts";
export interface Options { /** The list of extensions this plugin applies to */ extensions?: string[];
/** The css selector to apply prism */ cssSelector?: string;}
// Default optionsexport const defaults: Options = { extensions: [".html"], cssSelector: "pre code",};
/** A plugin to syntax-highlight code using the prism library */export default function (userOptions?: Options) { const options = merge(defaults, userOptions);
return (site: Site) => { site.process(options.extensions, (pages) => pages.forEach(prism));
function prism(page: Page) { page.document!.querySelectorAll(options.cssSelector!) .forEach((element) => Prism.highlightElement(element)); } };}
Version Info