${callouts[calloutType]}
${title}
${collapse ? toggleIcon : ""}
`,
}
const blockquoteContent: (BlockContent | DefinitionContent)[] = [titleNode]
if (remainingText.length > 0) {
blockquoteContent.push({
type: "paragraph",
children: [
{
type: "text",
value: remainingText,
},
...restChildren,
],
})
}
// replace first line of blockquote with title and rest of the paragraph text
node.children.splice(0, 1, ...blockquoteContent)
// add properties to base blockquote
node.data = {
hProperties: {
...(node.data?.hProperties ?? {}),
className: `callout ${collapse ? "is-collapsible" : ""} ${
defaultState === "collapsed" ? "is-collapsed" : ""
}`,
"data-callout": calloutType,
"data-callout-fold": collapse,
},
}
}
})
}
})
}
if (opts.mermaid) {
plugins.push(() => {
return (tree: Root, _file) => {
visit(tree, "code", (node: Code) => {
if (node.lang === "mermaid") {
node.data = {
hProperties: {
className: ["mermaid"],
},
}
}
})
}
})
}
if (opts.parseTags) {
plugins.push(() => {
return (tree: Root, file) => {
const slug = canonicalizeServer(file.data.slug!)
const base = pathToRoot(slug)
findAndReplace(tree, tagRegex, (value: string, tag: string) => {
if (file.data.frontmatter) {
file.data.frontmatter.tags.push(tag)
}
return {
type: "link",
url: base + `/tags/${slugTag(tag)}`,
data: {
hProperties: {
className: ["tag-link"],
},
},
children: [
{
type: "text",
value,
},
],
}
})
}
})
}
return plugins
},
htmlPlugins() {
return [rehypeRaw]
},
externalResources() {
const js: JSResource[] = []
if (opts.callouts) {
js.push({
script: calloutScript,
loadTime: "afterDOMReady",
contentType: "inline",
})
}
if (opts.mermaid) {
js.push({
script: `
import mermaid from 'https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.esm.min.mjs';
document.addEventListener('nav', async () => {
const darkMode = document.documentElement.getAttribute('saved-theme') === 'dark'
mermaid.initialize({
securityLevel: 'loose',
theme: darkMode ? 'dark' : 'default'
});
});
`,
loadTime: "afterDOMReady",
moduleType: "module",
contentType: "inline",
})
}
return { js }
},
}
}