Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
feat(mind-map): quote the node a backlink was made from
Elian Doran8a6e1976d3d5
diff --git a/apps/client/src/widgets/type_widgets/MindMapNodePanel.tsx b/apps/client/src/widgets/type_widgets/MindMapNodePanel.tsxindex f58155f0a5..d4fa874917 100644--- a/apps/client/src/widgets/type_widgets/MindMapNodePanel.tsx+++ b/apps/client/src/widgets/type_widgets/MindMapNodePanel.tsx@@ -1,5 +1,6 @@import "./MindMapNodePanel.css";+import { parseMindMapNoteLink } from "@triliumnext/commons";import { Dropdown as BootstrapDropdown } from "bootstrap";import type { MindElixirInstance, NodeObj, TagObj } from "mind-elixir";import { ComponentChildren } from "preact";@@ -21,7 +22,7 @@ import NoteAutocomplete from "../react/NoteAutocomplete";import { refToJQuerySelector } from "../react/react_utils";import SegmentedChoice from "../react/SegmentedChoice";import { fitNodeImage, nearestNodeImageWidth, NODE_IMAGE_WIDTHS, uploadNodeImage } from "./helpers/mind_map_images";-import { describeExternalLink, getLinkedNotePath, linkFromSuggestion } from "./helpers/mind_map_links";+import { describeExternalLink, linkFromSuggestion } from "./helpers/mind_map_links";/*** The hues offered by the panel: as many of the shared palette as fit on a single row next to the@@ -506,7 +507,7 @@ function NodeLinkFace({ link, indeterminate }: { link: string | null, indeterminreturn <><Icon icon="bx bx-link" /><span className="mind-map-node-link-label mind-map-node-link-mixed">{t("mind-map.link-mixed")}</span></>;}- const notePath = getLinkedNotePath(link);+ const notePath = parseMindMapNoteLink(link)?.notePath;if (notePath) {return <LinkedNoteFace notePath={notePath} />;}diff --git a/apps/client/src/widgets/type_widgets/helpers/mind_map_links.spec.ts b/apps/client/src/widgets/type_widgets/helpers/mind_map_links.spec.tsindex 19a40220df..f8af77e81b 100644--- a/apps/client/src/widgets/type_widgets/helpers/mind_map_links.spec.ts+++ b/apps/client/src/widgets/type_widgets/helpers/mind_map_links.spec.ts@@ -1,7 +1,7 @@import type { Suggestion } from "../../../services/note_autocomplete";import { describe, expect, it } from "vitest";-import { describeExternalLink, getLinkedNotePath, getNodeLinkHref, linkFromSuggestion, renderNodeLinks } from "./mind_map_links";+import { describeExternalLink, getNodeLinkHref, linkFromSuggestion, renderNodeLinks } from "./mind_map_links";/** Builds the anchor Mind Elixir gives a node that carries a link. */function buildNodes(...links: string[]) {@@ -21,18 +21,6 @@ function anchors(nodes: HTMLElement) {return Array.from(nodes.querySelectorAll("a"));}-describe("getLinkedNotePath", () => {- it("tells a link to a note from one pointing outside Trilium", () => {- expect(getLinkedNotePath("#root/abc123")).toBe("root/abc123");- expect(getLinkedNotePath("#root/parent/abc123")).toBe("root/parent/abc123");- expect(getLinkedNotePath("#root")).toBe("root");-- for (const link of [ null, undefined, "", "https://example.com", "#rootless/abc", "root/abc123" ]) {- expect(getLinkedNotePath(link)).toBeNull();- }- });-});-describe("linkFromSuggestion", () => {it("stores a note as an in-app address and an external link as one we could follow", () => {expect(linkFromSuggestion({ notePath: "root/abc123" } as Suggestion)).toBe("#root/abc123");diff --git a/apps/client/src/widgets/type_widgets/helpers/mind_map_links.ts b/apps/client/src/widgets/type_widgets/helpers/mind_map_links.tsindex e061e1390c..c2d60dcbe7 100644--- a/apps/client/src/widgets/type_widgets/helpers/mind_map_links.ts+++ b/apps/client/src/widgets/type_widgets/helpers/mind_map_links.ts@@ -1,4 +1,4 @@-import { ALLOWED_PROTOCOLS } from "@triliumnext/commons";+import { ALLOWED_PROTOCOLS, parseMindMapNoteLink } from "@triliumnext/commons";import type { Suggestion } from "../../../services/note_autocomplete";import { normalizeExternalUrl } from "../../../utils/url";@@ -10,14 +10,11 @@ import { normalizeExternalUrl } from "../../../utils/url";* A link to a note is therefore written the way a note link is written everywhere else in Trilium,* as the in-app address `#root/…`. The delegated handler in `link.ts` picks a click up off any* anchor on the page, so a note opens with nothing else to wire up. Anything else is an address- * outside Trilium.+ * outside Trilium. What makes an address one or the other is `parseMindMapNoteLink`'s to say, which+ * lives with the rest of the note logic both ends share: the map is written here and read by the+ * scan that relates it to the notes it points at.*/-/** The note path a link points at, or `null` where it points somewhere else entirely. */-export function getLinkedNotePath(link: string | null | undefined): string | null {- return (link && /^#root(\/|$)/.test(link)) ? link.slice(1) : null;-}-/** The link to store for what was picked in the note autocomplete, or `null` if nothing was. */export function linkFromSuggestion(suggestion: Suggestion | null | undefined): string | null {if (suggestion?.notePath) {@@ -35,7 +32,7 @@ export function getNodeLinkHref(link: string | null | undefined): string | nullreturn null;}- if (getLinkedNotePath(link)) {+ if (parseMindMapNoteLink(link)) {return link;}@@ -77,7 +74,7 @@ export function renderNodeLinks(container: HTMLElement) {anchor.setAttribute("href", href ?? "about:blank");anchor.rel = "noopener noreferrer";- if (getLinkedNotePath(link)) {+ if (parseMindMapNoteLink(link)) {// A note opens where the map is, as it does from anywhere else; `_blank` would force a// tab of its own (see `goToLinkExt`), leaving the map for a click that meant to follow// a thought.diff --git a/packages/commons/src/lib/notes.spec.ts b/packages/commons/src/lib/notes.spec.tsindex 0783112515..63a6723cb9 100644--- a/packages/commons/src/lib/notes.spec.ts+++ b/packages/commons/src/lib/notes.spec.ts@@ -1,6 +1,6 @@import { describe, expect, it } from "vitest";-import { getImageAttachmentTitle, getNoteIcon, NOTE_TYPE_ICONS, NOTE_TYPE_IMAGE_ATTACHMENTS } from "./notes.js";+import { getImageAttachmentTitle, getNoteIcon, NOTE_TYPE_ICONS, NOTE_TYPE_IMAGE_ATTACHMENTS, parseMindMapNoteLink } from "./notes.js";import { NoteType } from "./rows.js";function buildArgs(overrides: {@@ -139,3 +139,25 @@ describe("getNoteIcon", () => {expect(icon).toBe("bx bx-book");});});++describe("parseMindMapNoteLink", () => {+ it("tells a link to a note from one pointing outside Trilium", () => {+ expect(parseMindMapNoteLink("#root/abc123")).toEqual({ notePath: "root/abc123", noteId: "abc123" });+ // The whole path is kept — it is what places the note — and the note is the end of it.+ expect(parseMindMapNoteLink("#root/parent/abc123")).toEqual({ notePath: "root/parent/abc123", noteId: "abc123" });+ expect(parseMindMapNoteLink("#root")).toEqual({ notePath: "root", noteId: "root" });++ for (const link of [+ null, undefined, "", 42,+ "https://example.com",+ // An address of its own that happens to carry a note path is still a page elsewhere.+ "https://example.com/#root/abc123",+ "#rootless/abc",+ // The address as Mind Elixir would hold it, or not at all.+ "root/abc123",+ "#root/abc123?bookmark=x"+ ]) {+ expect(parseMindMapNoteLink(link)).toBeNull();+ }+ });+});diff --git a/packages/commons/src/lib/notes.ts b/packages/commons/src/lib/notes.tsindex 3d92f7a633..a6dbac1883 100644--- a/packages/commons/src/lib/notes.ts+++ b/packages/commons/src/lib/notes.ts@@ -54,6 +54,29 @@ export function getImageAttachmentTitle(type: NoteType | null | undefined): strireturn (NOTE_TYPE_IMAGE_ATTACHMENTS as Partial<Record<NoteType, string>>)[type];}+/**+ * The note a mind map node's link points at, or `null` where it points somewhere else entirely.+ *+ * A node carries one link of its own — Mind Elixir's `hyperLink` — which the editor writes as the+ * in-app address a note link wears everywhere else in Trilium, so that following it is answered by+ * the delegated link handler with nothing else to wire up. The whole value has to be that address:+ * a page whose own address happens to carry `#root/…` is a page, not a link between notes.+ *+ * Shared, so that what writes a link, what follows one, and what relates the two notes to each+ * other all agree on what a link is.+ */+export function parseMindMapNoteLink(link: unknown): { notePath: string; noteId: string } | null {+ if (typeof link !== "string" || !/^#root(\/[a-zA-Z0-9_]+)*$/.test(link)) {+ return null;+ }++ const notePath = link.slice(1);+ return {+ notePath,+ noteId: notePath.split("/").at(-1) ?? notePath+ };+}+const FILE_MIME_MAPPINGS: Record<string, string> = {"application/pdf": "bx bxs-file-pdf","application/vnd.oasis.opendocument.text": "bx bxs-file-doc",diff --git a/packages/trilium-core/src/routes/api/note_map.spec.ts b/packages/trilium-core/src/routes/api/note_map.spec.tsindex 8b5b89a5be..ef977d5ef2 100644--- a/packages/trilium-core/src/routes/api/note_map.spec.ts+++ b/packages/trilium-core/src/routes/api/note_map.spec.ts@@ -455,6 +455,40 @@ describe("Note map service (branch coverage)", () => {]);expect(toolCallOnly).toEqual({ noteId: "chatTool", relationName: "internalLink" });});++ function mapBacklink(sourceId: string, nodeData: unknown) {+ const target = buildNote({ id: `${sourceId}_t`, title: "Map target" });+ buildNote({+ id: sourceId,+ title: "Map",+ type: "mindMap",+ "~internalLink": target.noteId,+ content: JSON.stringify({ nodeData })+ });+ const res = note_map.getBacklinks(req(target.noteId));+ return res.find((b) => b.noteId === sourceId) as any;+ }++ // As for chats, the excerpt HTML is covered by services/backlink_excerpts.spec.ts; these pin+ // how getBacklinks routes a map.+ it("mindMap backlinks: the node the link sits on is quoted instead of the relation name", () => {+ const backlink = mapBacklink("mapNode", {+ topic: "Root",+ children: [ { topic: "The node", hyperLink: "#root/mapNode_t" } ]+ });++ expect(backlink.relationName).toBeUndefined();+ expect(backlink.excerpts).toEqual([+ `<div class="ck-content backlink-excerpt">Root › <a class="backlink-link" href="#root/mapNode_t">The node</a></div>`+ ]);+ });++ it("mindMap backlinks: a map with no node to quote falls back to the relation name", () => {+ // The relation says the two are linked, but nothing in the map does — a map whose link was+ // taken off a node between the scan and the asking.+ const noNode = mapBacklink("mapGone", { topic: "Root", children: [] });+ expect(noNode).toEqual({ noteId: "mapGone", relationName: "internalLink" });+ });});let api: CoreApiTester;diff --git a/packages/trilium-core/src/routes/api/note_map.ts b/packages/trilium-core/src/routes/api/note_map.tsindex c0d5d3b57b..e6b9243aae 100644--- a/packages/trilium-core/src/routes/api/note_map.ts+++ b/packages/trilium-core/src/routes/api/note_map.ts@@ -4,7 +4,7 @@ import becca from "../../becca/becca";import type { BacklinkCountResponse, BacklinksResponse, NoteMapNote } from "@triliumnext/commons";import type { Request } from "express";-import { findExcerpts, findLlmChatExcerpts } from "../../services/backlink_excerpts";+import { findExcerpts, findLlmChatExcerpts, findMindMapExcerpts } from "../../services/backlink_excerpts";interface TreeLink {sourceNoteId: string;@@ -266,7 +266,7 @@ function getBacklinks(req: Request<{ noteId: string }>): BacklinksResponse {return getFilteredBacklinks(note).map((backlink) => {const sourceNote = backlink.note;- const supportsExcerpts = sourceNote.type === "text" || sourceNote.type === "llmChat";+ const supportsExcerpts = sourceNote.type === "text" || sourceNote.type === "llmChat" || sourceNote.type === "mindMap";if (!supportsExcerpts || backlinksWithExcerptCount > 50) {return {@@ -277,13 +277,12 @@ function getBacklinks(req: Request<{ noteId: string }>): BacklinksResponse {backlinksWithExcerptCount++;- const excerpts = sourceNote.type === "llmChat"- ? findLlmChatExcerpts(sourceNote.getContent().toString(), noteId)- : findExcerpts(sourceNote.getContent().toString(), noteId);+ const excerpts = findSourceExcerpts(sourceNote, noteId);- // A chat that references the note only through tool calls has no quotable prose;- // name the relation instead, as for other excerpt-less sources.- if (sourceNote.type === "llmChat" && excerpts.length === 0) {+ // A chat that references the note only through tool calls has no quotable prose, and a map+ // whose link sits somewhere its nodes are not has no node to quote; name the relation+ // instead, as for other excerpt-less sources.+ if (sourceNote.type !== "text" && excerpts.length === 0) {return {noteId: sourceNote.noteId,relationName: backlink.name@@ -297,6 +296,20 @@ function getBacklinks(req: Request<{ noteId: string }>): BacklinksResponse {});}+/** Quotes what surrounds a link, in the terms the note holding it is written in. */+function findSourceExcerpts(sourceNote: BNote, referencedNoteId: string): string[] {+ const content = sourceNote.getContent().toString();++ switch (sourceNote.type) {+ case "llmChat":+ return findLlmChatExcerpts(content, referencedNoteId);+ case "mindMap":+ return findMindMapExcerpts(content, referencedNoteId);+ default:+ return findExcerpts(content, referencedNoteId);+ }+}+function getBacklinkCount(req: Request<{ noteId: string }>): BacklinkCountResponse {const { noteId } = req.params;diff --git a/packages/trilium-core/src/services/backlink_excerpts.spec.ts b/packages/trilium-core/src/services/backlink_excerpts.spec.tsindex b577294c8f..36dd5074c0 100644--- a/packages/trilium-core/src/services/backlink_excerpts.spec.ts+++ b/packages/trilium-core/src/services/backlink_excerpts.spec.ts@@ -1,7 +1,7 @@import { describe, expect, it } from "vitest";import { buildNote } from "../test/becca_easy_mocking";-import { findLlmChatExcerpts } from "./backlink_excerpts";+import { findLlmChatExcerpts, findMindMapExcerpts } from "./backlink_excerpts";function chatContent(messages: unknown[]) {return JSON.stringify({ messages });@@ -99,3 +99,84 @@ describe("findLlmChatExcerpts", () => {expect(findLlmChatExcerpts(`{"messages": "not an array"}`, "excQuiet")).toEqual([]);});});++describe("findMindMapExcerpts", () => {+ /** A map of nodes, each given as `[topic, hyperLink]`, all hanging off the root. */+ function mapContent(root: unknown) {+ return JSON.stringify({ nodeData: root });+ }++ it("quotes the node the link sits on, led by the nodes it hangs from", () => {+ buildNote({ id: "excMapTarget", title: "Map target" });++ const excerpts = findMindMapExcerpts(mapContent({+ topic: "Project",+ children: [+ {+ topic: "Ideas <untried>",+ children: [+ { topic: "Rewrite the parser", hyperLink: "#root/excMapTarget" },+ { topic: "Something else", hyperLink: "https://example.com" }+ ]+ },+ { topic: "Done", hyperLink: "#root/excMapOther" }+ ]+ }), "excMapTarget");++ expect(excerpts).toHaveLength(1);+ expect(excerpts[0]).toBe(+ `<div class="ck-content backlink-excerpt">Project › Ideas <untried> › ` ++ `<a class="backlink-link" href="#root/excMapTarget">Rewrite the parser</a></div>`+ );+ });++ it("quotes every node linking to the note, the root among them", () => {+ buildNote({ id: "excMapTwice", title: "Twice" });++ const excerpts = findMindMapExcerpts(mapContent({+ topic: "Root",+ hyperLink: "#root/excMapTwice",+ children: [ { topic: "Child", hyperLink: "#root/excMapTwice" } ]+ }), "excMapTwice");++ expect(excerpts).toHaveLength(2);+ // The root hangs from nothing, so it is quoted on its own.+ expect(excerpts[0]).toContain(`>Root</a>`);+ expect(excerpts[0]).not.toContain("›");+ expect(excerpts[1]).toContain(`Root › <a class="backlink-link" href="#root/excMapTwice">Child</a>`);+ });++ it("names an unnamed node after the note it points at", () => {+ buildNote({ id: "excMapUnnamed", title: "The note itself" });++ const excerpts = findMindMapExcerpts(mapContent({+ topic: "Root",+ children: [ { topic: "", hyperLink: "#root/excMapUnnamed" } ]+ }), "excMapUnnamed");++ expect(excerpts[0]).toContain(`>The note itself</a>`);+ });++ it("drops the root end of a long trail rather than the node itself", () => {+ buildNote({ id: "excMapDeep", title: "Deep" });++ // Each level is well within the budget on its own; together they are not.+ const topics = [ "a".repeat(80), "b".repeat(80), "c".repeat(80) ];+ const deepest = { topic: "The node", hyperLink: "#root/excMapDeep" };+ const map = topics.reduceRight<unknown>((child, topic) => ({ topic, children: [ child ] }), deepest);++ const [ excerpt ] = findMindMapExcerpts(mapContent(map), "excMapDeep");++ expect(excerpt).toContain(`>The node</a>`);+ expect(excerpt).toContain("…");+ // The nearest ancestor is kept, the furthest dropped: it is the one that says the least.+ expect(excerpt).toContain("c".repeat(80));+ expect(excerpt).not.toContain("a".repeat(80));+ });++ it("quotes nothing from a map that links elsewhere, or from content it cannot read", () => {+ expect(findMindMapExcerpts(mapContent({ topic: "Root", hyperLink: "https://example.com" }), "excMapNone")).toEqual([]);+ expect(findMindMapExcerpts("not JSON at all", "excMapNone")).toEqual([]);+ expect(findMindMapExcerpts(`{"nodeData": "not a node"}`, "excMapNone")).toEqual([]);+ });+});diff --git a/packages/trilium-core/src/services/backlink_excerpts.ts b/packages/trilium-core/src/services/backlink_excerpts.tsindex 05e5c56bd7..0a3f22e05d 100644--- a/packages/trilium-core/src/services/backlink_excerpts.ts+++ b/packages/trilium-core/src/services/backlink_excerpts.ts@@ -6,8 +6,11 @@* anchors — a text note's content directly. {@link findLlmChatExcerpts} brings `llmChat` notes* to that same shape first: their assistant prose is markdown, rendered to HTML through the* shared pipeline the chat UI uses, with wiki-link anchors retitled from note ID to note title.+ * {@link findMindMapExcerpts} has no prose to quote at all, a map's links belonging to its nodes,+ * and writes its own fragments instead.*/+import { parseMindMapNoteLink } from "@triliumnext/commons";import { renderToHtml } from "@triliumnext/commons/src/lib/markdown_renderer.js";import { HTMLElement, parse, TextNode } from "node-html-parser";@@ -169,6 +172,83 @@ function collectAssistantProse(jsonContent: string): string {return blocks.join("\n\n");}+/**+ * The `mindMap` entry point. A map has no prose to quote: the link belongs to a node, so what is+ * quoted is the node itself — its own text as the link, led by the nodes it hangs from, which is+ * what says where in the map the link was made.+ *+ * @param jsonContent the map, as it is stored.+ * @param referencedNoteId the note the backlinks are being gathered for.+ * @returns one excerpt per node linking to that note.+ */+export function findMindMapExcerpts(jsonContent: string, referencedNoteId: string): string[] {+ let rootNode: unknown;+ try {+ rootNode = (JSON.parse(jsonContent) as { nodeData?: unknown }).nodeData;+ } catch {+ return [];+ }++ const excerpts: string[] = [];+ collectNodeExcerpts(rootNode, [], referencedNoteId, excerpts);+ return excerpts;+}++function collectNodeExcerpts(node: unknown, ancestors: string[], referencedNoteId: string, excerpts: string[]) {+ if (!node || typeof node !== "object") {+ return;+ }++ const { topic, hyperLink, children } = node as Record<string, unknown>;+ const nodeText = (typeof topic === "string" ? topic : "");++ if (parseMindMapNoteLink(hyperLink)?.noteId === referencedNoteId) {+ excerpts.push(buildNodeExcerpt(ancestors, nodeText, referencedNoteId));+ }++ if (Array.isArray(children)) {+ const trail = [ ...ancestors, nodeText ];+ for (const child of children) {+ collectNodeExcerpts(child, trail, referencedNoteId, excerpts);+ }+ }+}++/**+ * Quotes one node: the nodes it hangs from, then the node itself as the link.+ *+ * The trail is taken from the node upwards for as long as there is room, so what is dropped is the+ * root end — the part every node in the map shares, and so the part that says the least about where+ * this one sits.+ */+function buildNodeExcerpt(ancestors: string[], nodeText: string, referencedNoteId: string): string {+ // A node left unnamed has nothing of its own to read; the note it points at names it instead,+ // rather than leaving a link with no text to click.+ const linkText = nodeText || becca.notes[referencedNoteId]?.getTitleOrProtected() || referencedNoteId;++ const trail: string[] = [];+ let length = linkText.length;+ for (const ancestor of [ ...ancestors ].reverse()) {+ if (!ancestor) continue;+ if (length + ancestor.length + MIND_MAP_TRAIL_SEPARATOR.length > EXCERPT_CHAR_LIMIT) {+ trail.unshift("…");+ break;+ }+ trail.unshift(ancestor);+ length += ancestor.length + MIND_MAP_TRAIL_SEPARATOR.length;+ }++ const crumbs = trail+ .map((ancestor) => `${escapeHtml(ancestor)}${MIND_MAP_TRAIL_SEPARATOR}`)+ .join("");++ return `<div class="ck-content backlink-excerpt">${crumbs}` ++ `<a class="backlink-link" href="#root/${referencedNoteId}">${escapeHtml(linkText)}</a></div>`;+}++/** What stands between a node and the one it hangs from. */+const MIND_MAP_TRAIL_SEPARATOR = " › ";+/*** Renames the wiki-link anchors from the note ID (all the markdown source carries) to the* note's title. In the chat UI this decoration happens client-side, but excerpts are rendereddiff --git a/packages/trilium-core/src/services/notes.ts b/packages/trilium-core/src/services/notes.tsindex 98db221092..d3dd3b89ca 100644--- a/packages/trilium-core/src/services/notes.ts+++ b/packages/trilium-core/src/services/notes.ts@@ -1,4 +1,4 @@-import { type AttachmentRow, type AttributeRow, type BranchRow, dayjs, type NoteRow, NOTE_TYPE_IMAGE_ATTACHMENTS, type NoteType } from "@triliumnext/commons";+import { type AttachmentRow, type AttributeRow, type BranchRow, dayjs, type NoteRow, NOTE_TYPE_IMAGE_ATTACHMENTS, type NoteType, parseMindMapNoteLink } from "@triliumnext/commons";import { t } from "i18next";import { parse as parseHtml } from "node-html-parser";import url from "url";@@ -792,10 +792,10 @@ function findRelationMapLinks(content: string, foundLinks: FoundLink[]) {/*** Collects the notes a mind map's nodes link to.*- * A node carries one link of its own, which the editor writes as the in-app address a note link- * wears everywhere else (`#root/…`, see the client's `mind_map_links`); anything else is an address- * outside Trilium and is not a link between notes. The whole map is walked rather than only its- * nodes, so that a link stays found wherever Mind Elixir comes to keep one.+ * A node carries one link of its own, and what makes it a link to a note is+ * {@link parseMindMapNoteLink}'s to say; anything else is an address outside Trilium. The whole map+ * is walked rather than only its nodes, so that a link stays found wherever Mind Elixir comes to+ * keep one.*/export function findMindMapLinks(content: string, foundLinks: FoundLink[]) {try {@@ -818,7 +818,7 @@ function collectMindMapLinks(value: unknown, foundLinks: FoundLink[]) {}const record = value as Record<string, unknown>;- const noteId = getMindMapLinkTarget(record.hyperLink);+ const noteId = parseMindMapNoteLink(record.hyperLink)?.noteId;if (noteId) {foundLinks.push({name: "internalLink",@@ -831,18 +831,6 @@ function collectMindMapLinks(value: unknown, foundLinks: FoundLink[]) {}}-/**- * The note a link points at, or `null` where it points elsewhere. The whole value has to be the- * address, so that a page whose own address happens to carry `#root/…` is not read as a note.- */-function getMindMapLinkTarget(link: unknown): string | null {- if (typeof link !== "string" || !/^#root(\/[a-zA-Z0-9_]+)*$/.test(link)) {- return null;- }-- return link.split("/").at(-1)?.replace(/^#/, "") ?? null;-}-const imageUrlToAttachmentIdMapping: Record<string, string> = {};async function downloadImage(noteId: string, imageUrl: string) {