| | |
| | | import { JSResource } from "../../util/resources" |
| | | // @ts-ignore |
| | | import calloutScript from "../../components/scripts/callout.inline.ts" |
| | | // @ts-ignore |
| | | import checkboxScript from "../../components/scripts/checkbox.inline.ts" |
| | | import { FilePath, pathToRoot, slugTag, slugifyFilePath } from "../../util/path" |
| | | import { toHast } from "mdast-util-to-hast" |
| | | import { toHtml } from "hast-util-to-html" |
| | |
| | | enableInHtmlEmbed: boolean |
| | | enableYouTubeEmbed: boolean |
| | | enableVideoEmbed: boolean |
| | | enableCheckbox: boolean |
| | | } |
| | | |
| | | const defaultOptions: Options = { |
| | |
| | | enableInHtmlEmbed: false, |
| | | enableYouTubeEmbed: true, |
| | | enableVideoEmbed: true, |
| | | enableCheckbox: false, |
| | | } |
| | | |
| | | const calloutMapping = { |
| | |
| | | }) |
| | | } |
| | | |
| | | if (opts.enableCheckbox) { |
| | | plugins.push(() => { |
| | | return (tree: HtmlRoot, _file) => { |
| | | visit(tree, "element", (node) => { |
| | | if (node.tagName === "input" && node.properties.type === "checkbox") { |
| | | const isChecked = node.properties?.checked ?? false |
| | | node.properties = { |
| | | type: "checkbox", |
| | | disabled: false, |
| | | checked: isChecked, |
| | | class: "checkbox-toggle", |
| | | } |
| | | } |
| | | }) |
| | | } |
| | | }) |
| | | } |
| | | |
| | | return plugins |
| | | }, |
| | | externalResources() { |
| | | const js: JSResource[] = [] |
| | | |
| | | if (opts.enableCheckbox) { |
| | | js.push({ |
| | | script: checkboxScript, |
| | | loadTime: "afterDOMReady", |
| | | contentType: "inline", |
| | | }) |
| | | } |
| | | |
| | | if (opts.callouts) { |
| | | js.push({ |
| | | script: calloutScript, |
| | |
| | | if (opts.mermaid) { |
| | | js.push({ |
| | | script: ` |
| | | import mermaid from 'https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.esm.min.mjs'; |
| | | const darkMode = document.documentElement.getAttribute('saved-theme') === 'dark' |
| | | mermaid.initialize({ |
| | | startOnLoad: false, |
| | | securityLevel: 'loose', |
| | | theme: darkMode ? 'dark' : 'default' |
| | | }); |
| | | let mermaidImport = undefined |
| | | document.addEventListener('nav', async () => { |
| | | await mermaid.run({ |
| | | querySelector: '.mermaid' |
| | | }) |
| | | if (document.querySelector("code.mermaid")) { |
| | | mermaidImport ||= await import('https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.esm.min.mjs') |
| | | const mermaid = mermaidImport.default |
| | | const darkMode = document.documentElement.getAttribute('saved-theme') === 'dark' |
| | | mermaid.initialize({ |
| | | startOnLoad: false, |
| | | securityLevel: 'loose', |
| | | theme: darkMode ? 'dark' : 'default' |
| | | }) |
| | | |
| | | await mermaid.run({ |
| | | querySelector: '.mermaid' |
| | | }) |
| | | } |
| | | }); |
| | | `, |
| | | loadTime: "afterDOMReady", |