Fixed Obsidian Highlights parser

This commit is contained in:
Emile Bangma 2024-09-19 12:32:09 +00:00
parent e464dc9ced
commit f83ca160b8

View File

@ -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[]