2023-05-30 15:02:20 +00:00
|
|
|
import remarkGfm from "remark-gfm"
|
2023-07-23 00:27:41 +00:00
|
|
|
import smartypants from "remark-smartypants"
|
2023-05-30 15:02:20 +00:00
|
|
|
import { QuartzTransformerPlugin } from "../types"
|
2023-06-01 23:48:38 +00:00
|
|
|
import rehypeSlug from "rehype-slug"
|
2023-06-04 16:35:45 +00:00
|
|
|
import rehypeAutolinkHeadings from "rehype-autolink-headings"
|
2023-05-30 15:02:20 +00:00
|
|
|
|
|
|
|
export interface Options {
|
|
|
|
enableSmartyPants: boolean
|
2023-06-01 23:48:38 +00:00
|
|
|
linkHeadings: boolean
|
2023-05-30 15:02:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const defaultOptions: Options = {
|
2023-06-01 23:48:38 +00:00
|
|
|
enableSmartyPants: true,
|
2023-07-23 00:27:41 +00:00
|
|
|
linkHeadings: true,
|
2023-05-30 15:02:20 +00:00
|
|
|
}
|
|
|
|
|
2023-07-23 00:27:41 +00:00
|
|
|
export const GitHubFlavoredMarkdown: QuartzTransformerPlugin<Partial<Options> | undefined> = (
|
|
|
|
userOpts,
|
|
|
|
) => {
|
2023-06-12 06:26:43 +00:00
|
|
|
const opts = { ...defaultOptions, ...userOpts }
|
|
|
|
return {
|
|
|
|
name: "GitHubFlavoredMarkdown",
|
|
|
|
markdownPlugins() {
|
2023-07-02 20:08:29 +00:00
|
|
|
return opts.enableSmartyPants ? [remarkGfm, smartypants] : [remarkGfm]
|
2023-06-12 06:26:43 +00:00
|
|
|
},
|
|
|
|
htmlPlugins() {
|
|
|
|
if (opts.linkHeadings) {
|
2023-07-23 00:27:41 +00:00
|
|
|
return [
|
|
|
|
rehypeSlug,
|
|
|
|
[
|
|
|
|
rehypeAutolinkHeadings,
|
|
|
|
{
|
|
|
|
behavior: "append",
|
2023-12-03 17:22:16 +00:00
|
|
|
properties: {
|
|
|
|
ariaHidden: true,
|
|
|
|
tabIndex: -1,
|
|
|
|
"data-no-popover": true,
|
|
|
|
},
|
2023-07-23 00:27:41 +00:00
|
|
|
content: {
|
|
|
|
type: "text",
|
|
|
|
value: " §",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
]
|
2023-06-12 06:26:43 +00:00
|
|
|
} else {
|
|
|
|
return []
|
|
|
|
}
|
2023-07-23 00:27:41 +00:00
|
|
|
},
|
2023-05-30 15:02:20 +00:00
|
|
|
}
|
|
|
|
}
|