From 7caddf6230382db56ef969e137e44fbf5bd5d9d3 Mon Sep 17 00:00:00 2001 From: kanaupi Date: Sun, 15 Feb 2026 20:54:26 +0900 Subject: [PATCH] fix: prevent underscore emphasis in wikilink image filenames MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Image wikilinks like `![[my_photo_2024.png]]` are broken when the textTransform phase re-emits them as raw text, because the Markdown parser interprets `_photo_` as emphasis (`photo`), destroying the wikilink syntax before it can be resolved to an `` tag. Convert image embeds (`![[…]]`) with recognised image extensions to standard Markdown image syntax with angle-bracket destinations (`![alt]()`) early in the textTransform callback, so the Markdown parser sees a proper image node instead of raw text with underscores. Fixes #2291 Co-authored-by: Cursor --- quartz/plugins/transformers/ofm.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/quartz/plugins/transformers/ofm.ts b/quartz/plugins/transformers/ofm.ts index 7a523aa59..5b9f4b4d3 100644 --- a/quartz/plugins/transformers/ofm.ts +++ b/quartz/plugins/transformers/ofm.ts @@ -202,6 +202,17 @@ export const ObsidianFlavoredMarkdown: QuartzTransformerPlugin> return `${embedDisplay}[${displayAlias.replace(/^\|/, "")}](${rawFp})` } + // Convert image embeds to standard markdown to prevent underscores + // in filenames from being parsed as emphasis by the markdown parser. + // Uses angle-bracket destination syntax to preserve special characters. + if (embedDisplay === "!" && fp) { + const ext = path.extname(fp).toLowerCase() + if ([".png", ".jpg", ".jpeg", ".gif", ".bmp", ".svg", ".webp"].includes(ext)) { + const alt = displayAlias ? displayAlias.replace(/^\|/, "").trim() : "" + return `![${alt}](<${fp}>)` + } + } + return `${embedDisplay}[[${fp}${displayAnchor}${displayAlias}]]` }) }