mirror of
https://github.com/jackyzha0/quartz.git
synced 2026-03-24 15:05:42 -05:00
Obsidian Parsers (Highlights)
This commit is contained in:
parent
e697696a20
commit
d9e0e0bffb
@ -0,0 +1,40 @@
|
||||
import { QuartzTransformerPlugin } from "../../types"
|
||||
import { ReplaceFunction, findAndReplace as mdastFindReplace } from "mdast-util-find-and-replace"
|
||||
import { Root } from "mdast"
|
||||
|
||||
interface Options {
|
||||
enabled: Boolean
|
||||
}
|
||||
|
||||
const defaultOptions: Options = {
|
||||
enabled: true,
|
||||
}
|
||||
|
||||
const highlightRegex = new RegExp(/==([^=]+)==/g)
|
||||
|
||||
export const ObsidianMarkdownHighlights: QuartzTransformerPlugin<Partial<Options>> = (userOpts) => {
|
||||
const opts: Options = { ...defaultOptions, ...userOpts }
|
||||
return {
|
||||
name: "ObsidianMarkdownHighlights",
|
||||
markdownPlugins() {
|
||||
return [
|
||||
(tree: Root) => {
|
||||
if (opts.enabled) {
|
||||
const replacements: [RegExp, string | ReplaceFunction][] = []
|
||||
replacements.push([
|
||||
highlightRegex,
|
||||
(_value: string, ...capture: string[]) => {
|
||||
const [inner] = capture
|
||||
return {
|
||||
type: "html",
|
||||
value: `<span class="text-highlight">${inner}</span>`,
|
||||
}
|
||||
},
|
||||
])
|
||||
mdastFindReplace(tree, replacements)
|
||||
}
|
||||
},
|
||||
]
|
||||
},
|
||||
}
|
||||
}
|
||||
@ -1 +1,2 @@
|
||||
export { ObsidianMarkdownArrow } from "./arrows"
|
||||
export { ObsidianMarkdownHighlights } from "./highlights"
|
||||
|
||||
@ -35,7 +35,7 @@ import smartypants from "remark-smartypants"
|
||||
import rehypeSlug from "rehype-slug"
|
||||
import rehypeAutolinkHeadings from "rehype-autolink-headings"
|
||||
|
||||
import { ObsidianMarkdownArrow } from "../parsers/obsidian"
|
||||
import { ObsidianMarkdownArrow, ObsidianMarkdownHighlights } from "../parsers/obsidian"
|
||||
|
||||
export interface CommonMarkOptions {
|
||||
option1: Boolean
|
||||
@ -183,6 +183,8 @@ export const ObsidianFlavoredMarkdown: QuartzTransformerPlugin<Partial<ObsidianO
|
||||
//const replacements: [RegExp, string | ReplaceFunction][] = []
|
||||
//const base = pathToRoot(file.data.slug!)
|
||||
|
||||
ObsidianMarkdownHighlights({ enabled: opts.highlight })
|
||||
|
||||
ObsidianMarkdownArrow({ enabled: opts.parseArrows })
|
||||
|
||||
//mdastFindReplace(tree, replacements)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user