Fixed highlight syntax not working if there are other embedded formats

This commit is contained in:
Stephen Tse 2025-04-19 14:06:52 -07:00
parent c238dd16d9
commit 5acfbcb291

View File

@ -126,7 +126,7 @@ export const tableRegex = new RegExp(/^\|([^\n])+\|\n(\|)( ?:?-{3,}:? ?\|)+\n(\|
// matches any wikilink, only used for escaping wikilinks inside tables
export const tableWikilinkRegex = new RegExp(/(!?\[\[[^\]]*?\]\]|\[\^[^\]]*?\])/g)
const highlightRegex = new RegExp(/==([^=]+)==/g)
const highlightRegex = new RegExp(/==([^=]+?)==/g)
const commentRegex = new RegExp(/%%[\s\S]*?%%/g)
// from https://github.com/escwxyz/remark-obsidian-callout/blob/main/src/index.ts
const calloutRegex = new RegExp(/^\[\!([\w-]+)\|?(.+?)?\]([+-]?)/)
@ -203,6 +203,12 @@ export const ObsidianFlavoredMarkdown: QuartzTransformerPlugin<Partial<Options>>
})
}
// pre-transform highlights
if (opts.highlight) {
src = src.replace(highlightRegex,
`<span class="text-highlight">$1</span>`)
}
return src
},
markdownPlugins(_ctx) {
@ -291,19 +297,6 @@ export const ObsidianFlavoredMarkdown: QuartzTransformerPlugin<Partial<Options>>
])
}
if (opts.highlight) {
replacements.push([
highlightRegex,
(_value: string, ...capture: string[]) => {
const [inner] = capture
return {
type: "html",
value: `<span class="text-highlight">${inner}</span>`,
}
},
])
}
if (opts.parseArrows) {
replacements.push([
arrowRegex,