From 961a219f618e8b61a432c966d2d8dfc2df22cf2c Mon Sep 17 00:00:00 2001 From: Ola Rubaj <52197250+olayway@users.noreply.github.com> Date: Fri, 11 Aug 2023 18:07:02 +0200 Subject: [PATCH] [remark-wiki-link][m]: parse note embeds as regular wiki links - temporary solution before we have a proper note embed support --- .../remark-wiki-link/src/lib/fromMarkdown.ts | 31 +++++++++++++------ packages/remark-wiki-link/src/lib/html.ts | 17 +++++++--- .../test/micromarkExtensionWikiLink.spec.ts | 12 +++++++ .../test/remarkWikiLink.spec.ts | 24 ++++++++++++++ 4 files changed, 70 insertions(+), 14 deletions(-) diff --git a/packages/remark-wiki-link/src/lib/fromMarkdown.ts b/packages/remark-wiki-link/src/lib/fromMarkdown.ts index 469cd2e0..6d52180c 100644 --- a/packages/remark-wiki-link/src/lib/fromMarkdown.ts +++ b/packages/remark-wiki-link/src/lib/fromMarkdown.ts @@ -15,9 +15,9 @@ const defaultWikiLinkResolver = (target: string) => { export interface FromMarkdownOptions { pathFormat?: - | "raw" // default; use for regular relative or absolute paths - | "obsidian-absolute" // use for Obsidian-style absolute paths (with no leading slash) - | "obsidian-short"; // use for Obsidian-style shortened paths (shortest path possible) + | "raw" // default; use for regular relative or absolute paths + | "obsidian-absolute" // use for Obsidian-style absolute paths (with no leading slash) + | "obsidian-short"; // use for Obsidian-style shortened paths (shortest path possible) permalinks?: string[]; // list of permalinks to match possible permalinks of a wiki link against wikiLinkResolver?: (name: string) => string[]; // function to resolve wiki links to an array of possible permalinks newClassName?: string; // class name to add to links that don't have a matching permalink @@ -125,13 +125,24 @@ function fromMarkdown(opts: FromMarkdownOptions = {}) { if (isEmbed) { const [isSupportedFormat, format] = isSupportedFileFormat(target); if (!isSupportedFormat) { - wikiLink.data.hName = "p"; - wikiLink.data.hChildren = [ - { - type: "text", - value: `![[${target}]]`, - }, - ]; + // Temporarily render note transclusion as a regular wiki link + if (!format) { + wikiLink.data.hName = "a"; + wikiLink.data.hProperties = { + className: classNames + " " + "transclusion", + href: hrefTemplate(link) + headingId, + }; + wikiLink.data.hChildren = [{ type: "text", value: displayName }]; + + } else { + wikiLink.data.hName = "p"; + wikiLink.data.hChildren = [ + { + type: "text", + value: `![[${target}]]`, + }, + ]; + } } else if (format === "pdf") { wikiLink.data.hName = "iframe"; wikiLink.data.hProperties = { diff --git a/packages/remark-wiki-link/src/lib/html.ts b/packages/remark-wiki-link/src/lib/html.ts index 8f23278d..d4a7996f 100644 --- a/packages/remark-wiki-link/src/lib/html.ts +++ b/packages/remark-wiki-link/src/lib/html.ts @@ -15,9 +15,9 @@ const defaultWikiLinkResolver = (target: string) => { export interface HtmlOptions { pathFormat?: - | "raw" // default; use for regular relative or absolute paths - | "obsidian-absolute" // use for Obsidian-style absolute paths (with no leading slash) - | "obsidian-short"; // use for Obsidian-style shortened paths (shortest path possible) + | "raw" // default; use for regular relative or absolute paths + | "obsidian-absolute" // use for Obsidian-style absolute paths (with no leading slash) + | "obsidian-short"; // use for Obsidian-style shortened paths (shortest path possible) permalinks?: string[]; // list of permalinks to match possible permalinks of a wiki link against wikiLinkResolver?: (name: string) => string[]; // function to resolve wiki links to an array of possible permalinks newClassName?: string; // class name to add to links that don't have a matching permalink @@ -108,7 +108,16 @@ function html(opts: HtmlOptions = {}) { if (isEmbed) { const [isSupportedFormat, format] = isSupportedFileFormat(target); if (!isSupportedFormat) { - this.raw(`![[${target}]]`); + // Temporarily render note transclusion as a regular wiki link + if (!format) { + this.tag( + `` + ); + this.raw(displayName); + this.tag(""); + } else { + this.raw(`![[${target}]]`); + } } else if (format === "pdf") { this.tag( `