From 43a0830b09e485027d7f0834fc147713ec367e4f Mon Sep 17 00:00:00 2001 From: oldmartijntje Date: Sat, 6 Dec 2025 17:56:05 +0100 Subject: [PATCH] feat: add support for image scaling ![alt text|300](link) --- quartz/plugins/transformers/links.ts | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/quartz/plugins/transformers/links.ts b/quartz/plugins/transformers/links.ts index f4451d927..338568c8a 100644 --- a/quartz/plugins/transformers/links.ts +++ b/quartz/plugins/transformers/links.ts @@ -147,6 +147,28 @@ export const CrawlLinks: QuartzTransformerPlugin> = (userOpts) node.properties.loading = "lazy" } + // Check if this is an img tag with width specification in alt text + if (node.tagName === "img" && typeof node.properties.alt === "string") { + const altText = node.properties.alt as string + + // Check for Obsidian syntax: "alt text|300" + const obsidianMatch = altText.match(/^(.+?)\|(\d+)$/) + if (obsidianMatch) { + const realAltText = obsidianMatch[1].trim() + const width = obsidianMatch[2] + node.properties.style = `width: ${width}px;` + node.properties.alt = realAltText + } else { + // Check for numbers: "![300](image.jpg)" + const numberMatch = altText.match(/^(\d+)$/) + if (numberMatch) { + const width = numberMatch[1] + node.properties.style = `width: ${width}px;` + node.properties.alt = "" // or should we keep the alt text the number? + } + } + } + if (!isAbsoluteUrl(node.properties.src, { httpOnly: false })) { let dest = node.properties.src as RelativeURL dest = node.properties.src = transformLink(