mirror of
https://github.com/jackyzha0/quartz.git
synced 2025-12-27 23:04:05 -06:00
Fixed Obsidian Highlights parser
This commit is contained in:
parent
e464dc9ced
commit
f83ca160b8
@ -2,7 +2,7 @@ import { QuartzParserPlugin } from "../../types"
|
||||
import { ReplaceFunction, findAndReplace as mdastFindReplace } from "mdast-util-find-and-replace"
|
||||
import { JSResource } from "../../../util/resources"
|
||||
import { Root } from "mdast"
|
||||
import { PluggableList } from "unified"
|
||||
import { Pluggable } from "unified"
|
||||
|
||||
interface Options {
|
||||
enabled: Boolean
|
||||
@ -25,27 +25,27 @@ export const ObsidianHighlights: QuartzParserPlugin<Partial<Options>> = (userOpt
|
||||
return src
|
||||
},
|
||||
markdownPlugins(_ctx) {
|
||||
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)
|
||||
}
|
||||
},
|
||||
] as PluggableList
|
||||
const plug: Pluggable = (tree: Root, _path) => {
|
||||
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)
|
||||
}
|
||||
}
|
||||
return plug
|
||||
},
|
||||
htmlPlugins(_ctx) {
|
||||
return [] as PluggableList
|
||||
const plug: Pluggable = () => {}
|
||||
return plug
|
||||
},
|
||||
externalResources(_ctx) {
|
||||
const js = [] as JSResource[]
|
||||
|
||||
Loading…
Reference in New Issue
Block a user