From 06426c8f7e87e9476e3ede9f9d15771db601e3e6 Mon Sep 17 00:00:00 2001 From: Jacky Zhao Date: Wed, 15 Nov 2023 19:27:54 -0800 Subject: [PATCH] feat: support repeated anchor tag (closes #592) --- quartz/plugins/transformers/ofm.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/quartz/plugins/transformers/ofm.ts b/quartz/plugins/transformers/ofm.ts index a8399d011..9ae99228c 100644 --- a/quartz/plugins/transformers/ofm.ts +++ b/quartz/plugins/transformers/ofm.ts @@ -110,7 +110,7 @@ function canonicalizeCallout(calloutName: string): keyof typeof callouts { // ([^\[\]\|\#]+) -> one or more non-special characters ([,],|, or #) (name) // (#[^\[\]\|\#]+)? -> # then one or more non-special characters (heading link) // (|[^\[\]\|\#]+)? -> | then one or more non-special characters (alias) -const wikilinkRegex = new RegExp(/!?\[\[([^\[\]\|\#]+)?(#[^\[\]\|\#]+)?(\|[^\[\]\|\#]+)?\]\]/, "g") +const wikilinkRegex = new RegExp(/!?\[\[([^\[\]\|\#]+)?(#+[^\[\]\|\#]+)?(\|[^\[\]\|\#]+)?\]\]/, "g") const highlightRegex = new RegExp(/==([^=]+)==/, "g") const commentRegex = new RegExp(/%%(.+)%%/, "g") // from https://github.com/escwxyz/remark-obsidian-callout/blob/main/src/index.ts @@ -178,9 +178,9 @@ export const ObsidianFlavoredMarkdown: QuartzTransformerPlugin src = src.replaceAll(wikilinkRegex, (value, ...capture) => { const [rawFp, rawHeader, rawAlias] = capture const fp = rawFp ?? "" - const anchor = rawHeader?.trim().slice(1) + const anchor = rawHeader?.trim().replace(/^#+/, "") const displayAnchor = anchor ? `#${slugAnchor(anchor)}` : "" - const displayAlias = rawAlias ?? rawHeader?.replace("#", "|") ?? "" + const displayAlias = rawAlias ?? anchor ?? "" const embedDisplay = value.startsWith("!") ? "!" : "" return `${embedDisplay}[[${fp}${displayAnchor}${displayAlias}]]` })