Skip to content

Commit f4d6e98

Browse files
committed
feat(print/list): rewrite links
1 parent eee496a commit f4d6e98

File tree

2 files changed

+36
-22
lines changed

2 files changed

+36
-22
lines changed

apps/client/src/services/link.ts

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -467,28 +467,30 @@ function getReferenceLinkTitleSync(href: string) {
467467
}
468468
}
469469

470-
// TODO: Check why the event is not supported.
471-
//@ts-ignore
472-
$(document).on("click", "a", goToLink);
473-
// TODO: Check why the event is not supported.
474-
//@ts-ignore
475-
$(document).on("auxclick", "a", goToLink); // to handle the middle button
476-
// TODO: Check why the event is not supported.
477-
//@ts-ignore
478-
$(document).on("contextmenu", "a", linkContextMenu);
479-
// TODO: Check why the event is not supported.
480-
//@ts-ignore
481-
$(document).on("dblclick", "a", goToLink);
482-
483-
$(document).on("mousedown", "a", (e) => {
484-
if (e.which === 2) {
485-
// prevent paste on middle click
486-
// https://github.com/zadam/trilium/issues/2995
487-
// https://developer.mozilla.org/en-US/docs/Web/API/Element/auxclick_event#preventing_default_actions
488-
e.preventDefault();
489-
return false;
490-
}
491-
});
470+
if (glob.device !== "print") {
471+
// TODO: Check why the event is not supported.
472+
//@ts-ignore
473+
$(document).on("click", "a", goToLink);
474+
// TODO: Check why the event is not supported.
475+
//@ts-ignore
476+
$(document).on("auxclick", "a", goToLink); // to handle the middle button
477+
// TODO: Check why the event is not supported.
478+
//@ts-ignore
479+
$(document).on("contextmenu", "a", linkContextMenu);
480+
// TODO: Check why the event is not supported.
481+
//@ts-ignore
482+
$(document).on("dblclick", "a", goToLink);
483+
484+
$(document).on("mousedown", "a", (e) => {
485+
if (e.which === 2) {
486+
// prevent paste on middle click
487+
// https://github.com/zadam/trilium/issues/2995
488+
// https://developer.mozilla.org/en-US/docs/Web/API/Element/auxclick_event#preventing_default_actions
489+
e.preventDefault();
490+
return false;
491+
}
492+
});
493+
}
492494

493495
export default {
494496
getNotePathFromUrl,

apps/client/src/widgets/collections/legacy/ListPrintView.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export function ListPrintView({ note, noteIds: unfilteredNoteIds, onReady }: Vie
2929

3030
insertPageTitle(contentEl, note.title);
3131
rewriteHeadings(contentEl, depth);
32+
rewriteLinks(contentEl);
3233

3334
notesWithContent.push({ note, content: { __html: contentEl.innerHTML } });
3435

@@ -84,3 +85,14 @@ function rewriteHeadings(contentEl: HTMLElement, depth: number) {
8485
headingEl.replaceWith(newHeadingEl);
8586
}
8687
}
88+
89+
function rewriteLinks(contentEl: HTMLElement) {
90+
const linkEls = contentEl.querySelectorAll("a");
91+
for (const linkEl of linkEls) {
92+
const href = linkEl.getAttribute("href");
93+
if (href && href.startsWith("#root/")) {
94+
const noteId = href.split("/").at(-1);
95+
linkEl.setAttribute("href", `#note-${noteId}`);
96+
}
97+
}
98+
}

0 commit comments

Comments
 (0)