mirror of
https://github.com/alrayyes/wiki.git
synced 2024-11-23 03:56:23 +00:00
51 lines
1.2 KiB
TypeScript
51 lines
1.2 KiB
TypeScript
import remarkGfm from "remark-gfm"
|
|
import smartypants from "remark-smartypants"
|
|
import { QuartzTransformerPlugin } from "../types"
|
|
import rehypeSlug from "rehype-slug"
|
|
import rehypeAutolinkHeadings from "rehype-autolink-headings"
|
|
|
|
export interface Options {
|
|
enableSmartyPants: boolean
|
|
linkHeadings: boolean
|
|
}
|
|
|
|
const defaultOptions: Options = {
|
|
enableSmartyPants: true,
|
|
linkHeadings: true,
|
|
}
|
|
|
|
export const GitHubFlavoredMarkdown: QuartzTransformerPlugin<Partial<Options> | undefined> = (
|
|
userOpts,
|
|
) => {
|
|
const opts = { ...defaultOptions, ...userOpts }
|
|
return {
|
|
name: "GitHubFlavoredMarkdown",
|
|
markdownPlugins() {
|
|
return opts.enableSmartyPants ? [remarkGfm, smartypants] : [remarkGfm]
|
|
},
|
|
htmlPlugins() {
|
|
if (opts.linkHeadings) {
|
|
return [
|
|
rehypeSlug,
|
|
[
|
|
rehypeAutolinkHeadings,
|
|
{
|
|
behavior: "append",
|
|
properties: {
|
|
ariaHidden: true,
|
|
tabIndex: -1,
|
|
"data-no-popover": true,
|
|
},
|
|
content: {
|
|
type: "text",
|
|
value: " §",
|
|
},
|
|
},
|
|
],
|
|
]
|
|
} else {
|
|
return []
|
|
}
|
|
},
|
|
}
|
|
}
|