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"
|
|
|
|
import rehypeAutolinkHeadings from "rehype-autolink-headings/lib"
|
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
|
|
|
}
|
|
|
|
|
|
|
|
export class GitHubFlavoredMarkdown extends QuartzTransformerPlugin {
|
|
|
|
name = "GitHubFlavoredMarkdown"
|
|
|
|
opts: Options
|
|
|
|
|
|
|
|
constructor(opts?: Options) {
|
|
|
|
super()
|
|
|
|
this.opts = { ...defaultOptions, ...opts }
|
|
|
|
}
|
|
|
|
|
|
|
|
markdownPlugins(): PluggableList {
|
|
|
|
return this.opts.enableSmartyPants ? [remarkGfm] : [remarkGfm, smartypants]
|
|
|
|
}
|
|
|
|
|
|
|
|
htmlPlugins(): PluggableList {
|
2023-06-02 06:48:38 +07:00
|
|
|
return this.opts.linkHeadings
|
|
|
|
? [rehypeSlug, [rehypeAutolinkHeadings, {
|
|
|
|
behavior: 'append', content: {
|
|
|
|
type: 'text',
|
|
|
|
value: '§'
|
|
|
|
}
|
|
|
|
}]]
|
|
|
|
: []
|
2023-05-30 22:02:20 +07:00
|
|
|
}
|
|
|
|
}
|