/
prism.ts
33 lines (26 loc) 路 894 Bytes
/
prism.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import 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 options
export 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));
}
};
}