mirror of
https://github.com/jackyzha0/quartz.git
synced 2025-12-27 23:04:05 -06:00
Obsidian Parsers (Arrow)
This commit is contained in:
parent
add7f3ab2e
commit
23e71e95f4
@ -0,0 +1,42 @@
|
||||
import { QuartzTransformerPlugin } from "../../types"
|
||||
import { ReplaceFunction, findAndReplace as mdastFindReplace } from "mdast-util-find-and-replace"
|
||||
import { SKIP } from "unist-util-visit"
|
||||
import { Root } from "mdast"
|
||||
|
||||
const arrowMapping: Record<string, string> = {
|
||||
"->": "→",
|
||||
"-->": "⇒",
|
||||
"=>": "⇒",
|
||||
"==>": "⇒",
|
||||
"<-": "←",
|
||||
"<--": "⇐",
|
||||
"<=": "⇐",
|
||||
"<==": "⇐",
|
||||
}
|
||||
|
||||
const arrowRegex = new RegExp(/(-{1,2}>|={1,2}>|<-{1,2}|<={1,2})/g)
|
||||
|
||||
export const ObsidianMarkdownArrow: QuartzTransformerPlugin = () => {
|
||||
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)
|
||||
},
|
||||
]
|
||||
},
|
||||
}
|
||||
}
|
||||
@ -0,0 +1 @@
|
||||
export { ObsidianMarkdownArrow } from "./arrows"
|
||||
@ -35,6 +35,8 @@ import smartypants from "remark-smartypants"
|
||||
import rehypeSlug from "rehype-slug"
|
||||
import rehypeAutolinkHeadings from "rehype-autolink-headings"
|
||||
|
||||
import { ObsidianMarkdownArrow } from "../parsers/obsidian"
|
||||
|
||||
export interface CommonMarkOptions {
|
||||
option1: Boolean
|
||||
}
|
||||
@ -170,6 +172,39 @@ export const ObsidianFlavoredMarkdown: QuartzTransformerPlugin<Partial<ObsidianO
|
||||
const opts = { ...defaultObsidianOptions, ...userOpts }
|
||||
return {
|
||||
name: "ObsidianFlavoredMarkdown",
|
||||
textTransform(_ctx, src) {
|
||||
return src
|
||||
},
|
||||
markdownPlugins(_ctx) {
|
||||
const plugins: PluggableList = []
|
||||
|
||||
plugins.push(() => {
|
||||
return (tree: Root, file) => {
|
||||
//const replacements: [RegExp, string | ReplaceFunction][] = []
|
||||
//const base = pathToRoot(file.data.slug!)
|
||||
|
||||
if (opts.parseArrows) {
|
||||
ObsidianMarkdownArrow()
|
||||
}
|
||||
|
||||
//mdastFindReplace(tree, replacements)
|
||||
}
|
||||
})
|
||||
|
||||
return plugins
|
||||
},
|
||||
htmlPlugins() {
|
||||
const plugins: PluggableList = [rehypeRaw]
|
||||
|
||||
plugins.push(() => {})
|
||||
|
||||
return plugins
|
||||
},
|
||||
externalResources() {
|
||||
const js: JSResource[] = []
|
||||
|
||||
return { js }
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user