forked from banthony101/union
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmarkdown.config.ts
More file actions
44 lines (41 loc) · 1.31 KB
/
Copy pathmarkdown.config.ts
File metadata and controls
44 lines (41 loc) · 1.31 KB
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
43
44
import { rehypeHeadingIds, type RemarkPlugin } from "@astrojs/markdown-remark"
import type { AstroUserConfig } from "astro/config"
import { escapeHTML } from "astro/runtime/server/escape.js"
import rehypeAutolinkHeadings from "rehype-autolink-headings"
import rehypeKatexPlugin from "rehype-katex"
import rehypeMathjaxPlugin from "rehype-mathjax"
import rehypeSlug from "rehype-slug"
import remarkMathPlugin from "remark-math"
import remarkSmartypants from "remark-smartypants"
import remarkToc from "remark-toc"
import { visit } from "unist-util-visit"
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>`
})
}
}