2023-05-30 18:02:20 +03:00
|
|
|
import { PluggableList } from "unified"
|
|
|
|
import remarkGfm from "remark-gfm"
|
|
|
|
import smartypants from 'remark-smartypants'
|
|
|
|
import { QuartzTransformerPlugin } from "../types"
|
2023-06-02 02:48:38 +03:00
|
|
|
import rehypeSlug from "rehype-slug"
|
2023-06-04 19:35:45 +03:00
|
|
|
import rehypeAutolinkHeadings from "rehype-autolink-headings"
|
2023-05-30 18:02:20 +03:00
|
|
|
|
|
|
|
export interface Options {
|
|
|
|
enableSmartyPants: boolean
|
2023-06-02 02:48:38 +03:00
|
|
|
linkHeadings: boolean
|
2023-05-30 18:02:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
const defaultOptions: Options = {
|
2023-06-02 02:48:38 +03:00
|
|
|
enableSmartyPants: true,
|
|
|
|
linkHeadings: true
|
2023-05-30 18:02:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
export class GitHubFlavoredMarkdown extends QuartzTransformerPlugin {
|
|
|
|
name = "GitHubFlavoredMarkdown"
|
|
|
|
opts: Options
|
|
|
|
|
2023-06-10 09:06:02 +03:00
|
|
|
constructor(opts?: Partial<Options>) {
|
2023-05-30 18:02:20 +03:00
|
|
|
super()
|
|
|
|
this.opts = { ...defaultOptions, ...opts }
|
|
|
|
}
|
|
|
|
|
|
|
|
markdownPlugins(): PluggableList {
|
|
|
|
return this.opts.enableSmartyPants ? [remarkGfm] : [remarkGfm, smartypants]
|
|
|
|
}
|
|
|
|
|
|
|
|
htmlPlugins(): PluggableList {
|
2023-06-02 02:48:38 +03:00
|
|
|
return this.opts.linkHeadings
|
|
|
|
? [rehypeSlug, [rehypeAutolinkHeadings, {
|
|
|
|
behavior: 'append', content: {
|
|
|
|
type: 'text',
|
2023-06-06 08:14:17 +03:00
|
|
|
value: ' §'
|
2023-06-02 02:48:38 +03:00
|
|
|
}
|
|
|
|
}]]
|
|
|
|
: []
|
2023-05-30 18:02:20 +03:00
|
|
|
}
|
|
|
|
}
|