Files
quartz-org-roam/org-garden/patches/04-oxhugofm-figure.patch
Ignacio Ballesteros 678fb315d3 feat: unified org-garden
2026-02-21 13:10:30 +01:00

45 lines
1.9 KiB
Diff

diff --git a/quartz/plugins/transformers/oxhugofm.ts b/quartz/plugins/transformers/oxhugofm.ts
index 303566e..4fb5e2c 100644
--- a/quartz/plugins/transformers/oxhugofm.ts
+++ b/quartz/plugins/transformers/oxhugofm.ts
@@ -27,7 +27,10 @@ const defaultOptions: Options = {
const relrefRegex = new RegExp(/\[([^\]]+)\]\(\{\{< relref "([^"]+)" >\}\}\)/, "g")
const predefinedHeadingIdRegex = new RegExp(/(.*) {#(?:.*)}/, "g")
const hugoShortcodeRegex = new RegExp(/{{(.*)}}/, "g")
-const figureTagRegex = new RegExp(/< ?figure src="(.*)" ?>/, "g")
+// Matches the full Hugo {{< figure src="..." ... >}} shortcode and captures src.
+// Must run before the generic shortcode stripper to avoid partial-match issues
+// with captions that contain HTML (e.g. <span class="figure-number">).
+const figureShortcodeRegex = new RegExp(/{{<\s*figure\b[^}]*\bsrc="([^"]*)"[^}]*>}}/, "g")
// \\\\\( -> matches \\(
// (.+?) -> Lazy match for capturing the equation
// \\\\\) -> matches \\)
@@ -70,19 +73,19 @@ export const OxHugoFlavouredMarkdown: QuartzTransformerPlugin<Partial<Options>>
})
}
- if (opts.removeHugoShortcode) {
+ if (opts.replaceFigureWithMdImg) {
src = src.toString()
- src = src.replaceAll(hugoShortcodeRegex, (_value, ...capture) => {
- const [scContent] = capture
- return scContent
+ src = src.replaceAll(figureShortcodeRegex, (_value, ...capture) => {
+ const [imgSrc] = capture
+ return `![](${imgSrc})`
})
}
- if (opts.replaceFigureWithMdImg) {
+ if (opts.removeHugoShortcode) {
src = src.toString()
- src = src.replaceAll(figureTagRegex, (_value, ...capture) => {
- const [src] = capture
- return `![](${src})`
+ src = src.replaceAll(hugoShortcodeRegex, (_value, ...capture) => {
+ const [scContent] = capture
+ return scContent
})
}