mirror of
https://github.com/jackyzha0/quartz.git
synced 2026-03-22 05:55:42 -05:00
fix: prevent underscore emphasis in wikilink image filenames
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 (`<em>photo</em>`), destroying the wikilink syntax before it can be resolved to an `<img>` tag. Convert image embeds (`![[…]]`) with recognised image extensions to standard Markdown image syntax with angle-bracket destinations (``) 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 <cursoragent@cursor.com>
This commit is contained in:
parent
ec00a40aef
commit
7caddf6230
@ -202,6 +202,17 @@ export const ObsidianFlavoredMarkdown: QuartzTransformerPlugin<Partial<Options>>
|
|||||||
return `${embedDisplay}[${displayAlias.replace(/^\|/, "")}](${rawFp})`
|
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 ``
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return `${embedDisplay}[[${fp}${displayAnchor}${displayAlias}]]`
|
return `${embedDisplay}[[${fp}${displayAnchor}${displayAlias}]]`
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user