2023-05-30 22:02:20 +07:00
|
|
|
import { PluggableList } from "unified"
|
|
|
|
import remarkGfm from "remark-gfm"
|
|
|
|
import smartypants from 'remark-smartypants'
|
|
|
|
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,
|
|
|
|
linkHeadings: true
|
2023-05-30 22:02:20 +07:00
|
|
|
}
|
|
|
|
|
2023-06-12 13:26:43 +07:00
|
|
|
export const GitHubFlavoredMarkdown: QuartzTransformerPlugin<Partial<Options> | undefined> = (userOpts) => {
|
|
|
|
const opts = { ...defaultOptions, ...userOpts }
|
|
|
|
return {
|
|
|
|
name: "GitHubFlavoredMarkdown",
|
|
|
|
markdownPlugins() {
|
|
|
|
return opts.enableSmartyPants ? [remarkGfm] : [remarkGfm, smartypants]
|
|
|
|
},
|
|
|
|
htmlPlugins() {
|
|
|
|
if (opts.linkHeadings) {
|
|
|
|
return [rehypeSlug, [rehypeAutolinkHeadings, {
|
|
|
|
behavior: 'append', content: {
|
|
|
|
type: 'text',
|
|
|
|
value: ' §'
|
|
|
|
}
|
|
|
|
}]]
|
|
|
|
} else {
|
|
|
|
return []
|
|
|
|
}
|
|
|
|
}
|
2023-05-30 22:02:20 +07:00
|
|
|
}
|
|
|
|
}
|