-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathmarkdown.config.ts
42 lines (39 loc) · 1.29 KB
/
markdown.config.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
34
35
36
37
38
39
40
41
42
import remarkToc from "remark-toc"
import rehypeSlug from "rehype-slug"
import { visit } from "unist-util-visit"
import remarkMathPlugin from "remark-math"
import rehypeKatexPlugin from "rehype-katex"
import rehypeMathjaxPlugin from "rehype-mathjax"
import remarkSmartypants from "remark-smartypants"
import type { AstroUserConfig } from "astro/config"
import { escapeHTML } from "astro/runtime/server/escape.js"
import rehypeAutolinkHeadings from "rehype-autolink-headings"
import { rehypeHeadingIds, type RemarkPlugin } from "@astrojs/markdown-remark"
type Markdown = AstroUserConfig["markdown"]
export const markdownConfiguration = {
gfm: true,
smartypants: false,
remarkPlugins: [
mermaid(),
remarkMathPlugin,
remarkSmartypants as RemarkPlugin,
[remarkToc, { heading: "contents", prefix: "toc-" }]
],
rehypePlugins: [
rehypeHeadingIds,
rehypeSlug,
[rehypeAutolinkHeadings, { behavior: "wrap" }],
rehypeKatexPlugin,
rehypeMathjaxPlugin
]
} satisfies Markdown
export function mermaid(): RemarkPlugin<Array<any>> {
return () => tree => {
visit(tree, "code", node => {
if (node.lang !== "mermaid") return
// @ts-expect-error
node.type = "html"
node.value = /* html */ `<div class="mermaid">${escapeHTML(node.value)}</div>`
})
}
}