From 6418dbb7e246fa17b56840c64daa043112dc9189 Mon Sep 17 00:00:00 2001
From: Ola Rubaj <52197250+olayway@users.noreply.github.com>
Date: Mon, 14 Aug 2023 15:23:28 +0200
Subject: [PATCH] [#1005, remark-wiki-link]: Parse note embeds as regular wiki
links (#1006)
---
.changeset/thick-worms-peel.md | 5 +++
.../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 ++++++++++++++
5 files changed, 75 insertions(+), 14 deletions(-)
create mode 100644 .changeset/thick-worms-peel.md
diff --git a/.changeset/thick-worms-peel.md b/.changeset/thick-worms-peel.md
new file mode 100644
index 00000000..7ced9765
--- /dev/null
+++ b/.changeset/thick-worms-peel.md
@@ -0,0 +1,5 @@
+---
+'@portaljs/remark-wiki-link': minor
+---
+
+Parse note embeds as regular wiki links (until we add proper support for note embeds).
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(
`