From f4d6e98d61127038662bf6941b83900e788ef656 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Thu, 20 Nov 2025 21:06:25 +0200 Subject: [PATCH] feat(print/list): rewrite links --- apps/client/src/services/link.ts | 44 ++++++++++--------- .../collections/legacy/ListPrintView.tsx | 12 +++++ 2 files changed, 35 insertions(+), 21 deletions(-) diff --git a/apps/client/src/services/link.ts b/apps/client/src/services/link.ts index 9af93b313..a596e7136 100644 --- a/apps/client/src/services/link.ts +++ b/apps/client/src/services/link.ts @@ -467,28 +467,30 @@ function getReferenceLinkTitleSync(href: string) { } } -// TODO: Check why the event is not supported. -//@ts-ignore -$(document).on("click", "a", goToLink); -// TODO: Check why the event is not supported. -//@ts-ignore -$(document).on("auxclick", "a", goToLink); // to handle the middle button -// TODO: Check why the event is not supported. -//@ts-ignore -$(document).on("contextmenu", "a", linkContextMenu); -// TODO: Check why the event is not supported. -//@ts-ignore -$(document).on("dblclick", "a", goToLink); +if (glob.device !== "print") { + // TODO: Check why the event is not supported. + //@ts-ignore + $(document).on("click", "a", goToLink); + // TODO: Check why the event is not supported. + //@ts-ignore + $(document).on("auxclick", "a", goToLink); // to handle the middle button + // TODO: Check why the event is not supported. + //@ts-ignore + $(document).on("contextmenu", "a", linkContextMenu); + // TODO: Check why the event is not supported. + //@ts-ignore + $(document).on("dblclick", "a", goToLink); -$(document).on("mousedown", "a", (e) => { - if (e.which === 2) { - // prevent paste on middle click - // https://github.com/zadam/trilium/issues/2995 - // https://developer.mozilla.org/en-US/docs/Web/API/Element/auxclick_event#preventing_default_actions - e.preventDefault(); - return false; - } -}); + $(document).on("mousedown", "a", (e) => { + if (e.which === 2) { + // prevent paste on middle click + // https://github.com/zadam/trilium/issues/2995 + // https://developer.mozilla.org/en-US/docs/Web/API/Element/auxclick_event#preventing_default_actions + e.preventDefault(); + return false; + } + }); +} export default { getNotePathFromUrl, diff --git a/apps/client/src/widgets/collections/legacy/ListPrintView.tsx b/apps/client/src/widgets/collections/legacy/ListPrintView.tsx index 07750a87b..d4fa36133 100644 --- a/apps/client/src/widgets/collections/legacy/ListPrintView.tsx +++ b/apps/client/src/widgets/collections/legacy/ListPrintView.tsx @@ -29,6 +29,7 @@ export function ListPrintView({ note, noteIds: unfilteredNoteIds, onReady }: Vie insertPageTitle(contentEl, note.title); rewriteHeadings(contentEl, depth); + rewriteLinks(contentEl); notesWithContent.push({ note, content: { __html: contentEl.innerHTML } }); @@ -84,3 +85,14 @@ function rewriteHeadings(contentEl: HTMLElement, depth: number) { headingEl.replaceWith(newHeadingEl); } } + +function rewriteLinks(contentEl: HTMLElement) { + const linkEls = contentEl.querySelectorAll("a"); + for (const linkEl of linkEls) { + const href = linkEl.getAttribute("href"); + if (href && href.startsWith("#root/")) { + const noteId = href.split("/").at(-1); + linkEl.setAttribute("href", `#note-${noteId}`); + } + } +}