Skip to content

Build your personal knowledge base with Trilium Notes

feat(print/list): rewrite links

Elian Doranf4d6e98d6112
diff --git a/apps/client/src/services/link.ts b/apps/client/src/services/link.ts
index 9af93b3135..a596e71366 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);
-
-$(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;
- }
-});
+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;
+ }
+ });
+}
export default {
getNotePathFromUrl,
diff --git a/apps/client/src/widgets/collections/legacy/ListPrintView.tsx b/apps/client/src/widgets/collections/legacy/ListPrintView.tsx
index 07750a87bb..d4fa361337 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}`);
+ }
+ }
+}