mirror of
https://github.com/jackyzha0/quartz.git
synced 2025-12-27 23:04:05 -06:00
Delegate options to parsers
This commit is contained in:
parent
03f4cb8b8a
commit
e697696a20
@ -3,6 +3,14 @@ import { ReplaceFunction, findAndReplace as mdastFindReplace } from "mdast-util-
|
||||
import { SKIP } from "unist-util-visit"
|
||||
import { Root } from "mdast"
|
||||
|
||||
interface Options {
|
||||
enabled: Boolean
|
||||
}
|
||||
|
||||
const defaultOptions: Options = {
|
||||
enabled: true,
|
||||
}
|
||||
|
||||
const arrowMapping: Record<string, string> = {
|
||||
"->": "→",
|
||||
"-->": "⇒",
|
||||
@ -16,25 +24,28 @@ const arrowMapping: Record<string, string> = {
|
||||
|
||||
const arrowRegex = new RegExp(/(-{1,2}>|={1,2}>|<-{1,2}|<={1,2})/g)
|
||||
|
||||
export const ObsidianMarkdownArrow: QuartzTransformerPlugin = () => {
|
||||
export const ObsidianMarkdownArrow: QuartzTransformerPlugin<Partial<Options>> = (userOpts) => {
|
||||
const opts: Options = { ...defaultOptions, ...userOpts }
|
||||
return {
|
||||
name: "ObsidianMarkdownArrow",
|
||||
markdownPlugins() {
|
||||
return [
|
||||
(tree: Root) => {
|
||||
const replacements: [RegExp, string | ReplaceFunction][] = []
|
||||
replacements.push([
|
||||
arrowRegex,
|
||||
(value: string, ..._capture: string[]) => {
|
||||
const maybeArrow = arrowMapping[value]
|
||||
if (maybeArrow === undefined) return SKIP
|
||||
return {
|
||||
type: "html",
|
||||
value: `<span>${maybeArrow}</span>`,
|
||||
}
|
||||
},
|
||||
])
|
||||
mdastFindReplace(tree, replacements)
|
||||
if (opts.enabled) {
|
||||
const replacements: [RegExp, string | ReplaceFunction][] = []
|
||||
replacements.push([
|
||||
arrowRegex,
|
||||
(value: string, ..._capture: string[]) => {
|
||||
const maybeArrow = arrowMapping[value]
|
||||
if (maybeArrow === undefined) return SKIP
|
||||
return {
|
||||
type: "html",
|
||||
value: `<span>${maybeArrow}</span>`,
|
||||
}
|
||||
},
|
||||
])
|
||||
mdastFindReplace(tree, replacements)
|
||||
}
|
||||
},
|
||||
]
|
||||
},
|
||||
|
||||
@ -183,9 +183,7 @@ export const ObsidianFlavoredMarkdown: QuartzTransformerPlugin<Partial<ObsidianO
|
||||
//const replacements: [RegExp, string | ReplaceFunction][] = []
|
||||
//const base = pathToRoot(file.data.slug!)
|
||||
|
||||
if (opts.parseArrows) {
|
||||
ObsidianMarkdownArrow()
|
||||
}
|
||||
ObsidianMarkdownArrow({ enabled: opts.parseArrows })
|
||||
|
||||
//mdastFindReplace(tree, replacements)
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user