2023-05-30 22:02:20 +07:00
|
|
|
import remarkGfm from "remark-gfm"
|
2023-07-23 07:27:41 +07:00
|
|
|
import smartypants from "remark-smartypants"
|
2023-05-30 22:02:20 +07:00
|
|
|
import { QuartzTransformerPlugin } from "../types"
|
2023-06-02 06:48:38 +07:00
|
|
|
import rehypeSlug from "rehype-slug"
|
2023-06-04 23:35:45 +07:00
|
|
|
import rehypeAutolinkHeadings from "rehype-autolink-headings"
|
2023-05-30 22:02:20 +07:00
|
|
|
|
|
|
|
export interface Options {
|
|
|
|
enableSmartyPants: boolean
|
2023-06-02 06:48:38 +07:00
|
|
|
linkHeadings: boolean
|
2023-05-30 22:02:20 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
const defaultOptions: Options = {
|
2023-06-02 06:48:38 +07:00
|
|
|
enableSmartyPants: true,
|
2023-07-23 07:27:41 +07:00
|
|
|
linkHeadings: true,
|
2023-05-30 22:02:20 +07:00
|
|
|
}
|
|
|
|
|
2023-07-23 07:27:41 +07:00
|
|
|
export const GitHubFlavoredMarkdown: QuartzTransformerPlugin<Partial<Options> | undefined> = (
|
|
|
|
userOpts,
|
|
|
|
) => {
|
2023-06-12 13:26:43 +07:00
|
|
|
const opts = { ...defaultOptions, ...userOpts }
|
|
|
|
return {
|
|
|
|
name: "GitHubFlavoredMarkdown",
|
|
|
|
markdownPlugins() {
|
2023-07-03 03:08:29 +07:00
|
|
|
return opts.enableSmartyPants ? [remarkGfm, smartypants] : [remarkGfm]
|
2023-06-12 13:26:43 +07:00
|
|
|
},
|
|
|
|
htmlPlugins() {
|
|
|
|
if (opts.linkHeadings) {
|
2023-07-23 07:27:41 +07:00
|
|
|
return [
|
|
|
|
rehypeSlug,
|
|
|
|
[
|
|
|
|
rehypeAutolinkHeadings,
|
|
|
|
{
|
|
|
|
behavior: "append",
|
2023-12-04 00:22:16 +07:00
|
|
|
properties: {
|
|
|
|
ariaHidden: true,
|
|
|
|
tabIndex: -1,
|
|
|
|
"data-no-popover": true,
|
|
|
|
},
|
2023-07-23 07:27:41 +07:00
|
|
|
content: {
|
2024-01-29 14:38:59 +07:00
|
|
|
type: "element",
|
|
|
|
tagName: "svg",
|
|
|
|
properties: {
|
|
|
|
width: 18,
|
|
|
|
height: 18,
|
|
|
|
viewBox: "0 0 24 24",
|
|
|
|
fill: "none",
|
|
|
|
stroke: "currentColor",
|
|
|
|
"stroke-width": "2",
|
|
|
|
"stroke-linecap": "round",
|
|
|
|
"stroke-linejoin": "round",
|
|
|
|
},
|
|
|
|
children: [
|
|
|
|
{
|
|
|
|
type: "element",
|
|
|
|
tagName: "path",
|
|
|
|
properties: {
|
|
|
|
d: "M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71",
|
|
|
|
},
|
|
|
|
children: [],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: "element",
|
|
|
|
tagName: "path",
|
|
|
|
properties: {
|
|
|
|
d: "M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71",
|
|
|
|
},
|
|
|
|
children: [],
|
|
|
|
},
|
|
|
|
],
|
2023-07-23 07:27:41 +07:00
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
]
|
2023-06-12 13:26:43 +07:00
|
|
|
} else {
|
|
|
|
return []
|
|
|
|
}
|
2023-07-23 07:27:41 +07:00
|
|
|
},
|
2023-05-30 22:02:20 +07:00
|
|
|
}
|
|
|
|
}
|