mirror of
https://github.com/jackyzha0/quartz.git
synced 2025-12-31 00:34: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 { SKIP } from "unist-util-visit"
|
||||||
import { Root } from "mdast"
|
import { Root } from "mdast"
|
||||||
|
|
||||||
|
interface Options {
|
||||||
|
enabled: Boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
const defaultOptions: Options = {
|
||||||
|
enabled: true,
|
||||||
|
}
|
||||||
|
|
||||||
const arrowMapping: Record<string, string> = {
|
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)
|
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 {
|
return {
|
||||||
name: "ObsidianMarkdownArrow",
|
name: "ObsidianMarkdownArrow",
|
||||||
markdownPlugins() {
|
markdownPlugins() {
|
||||||
return [
|
return [
|
||||||
(tree: Root) => {
|
(tree: Root) => {
|
||||||
const replacements: [RegExp, string | ReplaceFunction][] = []
|
if (opts.enabled) {
|
||||||
replacements.push([
|
const replacements: [RegExp, string | ReplaceFunction][] = []
|
||||||
arrowRegex,
|
replacements.push([
|
||||||
(value: string, ..._capture: string[]) => {
|
arrowRegex,
|
||||||
const maybeArrow = arrowMapping[value]
|
(value: string, ..._capture: string[]) => {
|
||||||
if (maybeArrow === undefined) return SKIP
|
const maybeArrow = arrowMapping[value]
|
||||||
return {
|
if (maybeArrow === undefined) return SKIP
|
||||||
type: "html",
|
return {
|
||||||
value: `<span>${maybeArrow}</span>`,
|
type: "html",
|
||||||
}
|
value: `<span>${maybeArrow}</span>`,
|
||||||
},
|
}
|
||||||
])
|
},
|
||||||
mdastFindReplace(tree, replacements)
|
])
|
||||||
|
mdastFindReplace(tree, replacements)
|
||||||
|
}
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|||||||
@ -183,9 +183,7 @@ export const ObsidianFlavoredMarkdown: QuartzTransformerPlugin<Partial<ObsidianO
|
|||||||
//const replacements: [RegExp, string | ReplaceFunction][] = []
|
//const replacements: [RegExp, string | ReplaceFunction][] = []
|
||||||
//const base = pathToRoot(file.data.slug!)
|
//const base = pathToRoot(file.data.slug!)
|
||||||
|
|
||||||
if (opts.parseArrows) {
|
ObsidianMarkdownArrow({ enabled: opts.parseArrows })
|
||||||
ObsidianMarkdownArrow()
|
|
||||||
}
|
|
||||||
|
|
||||||
//mdastFindReplace(tree, replacements)
|
//mdastFindReplace(tree, replacements)
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user