make %%init: ...%% in mermaid codeblock effective

only remove comments outside of codeblocks
This commit is contained in:
giselle197 2026-01-19 18:41:08 +08:00 committed by GitHub
parent f346a01296
commit 681491418e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -161,7 +161,13 @@ export const ObsidianFlavoredMarkdown: QuartzTransformerPlugin<Partial<Options>>
textTransform(_ctx, src) { textTransform(_ctx, src) {
// do comments at text level // do comments at text level
if (opts.comments) { if (opts.comments) {
src = src.replace(commentRegex, "") // Remove %% comments %% outside of codeblocks
const codeblockRegex = /```[\s\S]*?```|`[^`\n]+`/
const codeblockOrCommentRegex = new RegExp(
`(${codeblockRegex.source})|${commentRegex.source}`,
"g"
)
src = src.replace(codeblockOrCommentRegex, (match, codeblock) => codeblock ?? "")
} }
// pre-transform blockquotes // pre-transform blockquotes