feat(print/list): rewrite links

This commit is contained in:
Elian Doran 2025-11-20 21:06:25 +02:00
parent eee496a050
commit f4d6e98d61
No known key found for this signature in database
2 changed files with 35 additions and 21 deletions

View File

@ -467,6 +467,7 @@ function getReferenceLinkTitleSync(href: string) {
} }
} }
if (glob.device !== "print") {
// TODO: Check why the event is not supported. // TODO: Check why the event is not supported.
//@ts-ignore //@ts-ignore
$(document).on("click", "a", goToLink); $(document).on("click", "a", goToLink);
@ -489,6 +490,7 @@ $(document).on("mousedown", "a", (e) => {
return false; return false;
} }
}); });
}
export default { export default {
getNotePathFromUrl, getNotePathFromUrl,

View File

@ -29,6 +29,7 @@ export function ListPrintView({ note, noteIds: unfilteredNoteIds, onReady }: Vie
insertPageTitle(contentEl, note.title); insertPageTitle(contentEl, note.title);
rewriteHeadings(contentEl, depth); rewriteHeadings(contentEl, depth);
rewriteLinks(contentEl);
notesWithContent.push({ note, content: { __html: contentEl.innerHTML } }); notesWithContent.push({ note, content: { __html: contentEl.innerHTML } });
@ -84,3 +85,14 @@ function rewriteHeadings(contentEl: HTMLElement, depth: number) {
headingEl.replaceWith(newHeadingEl); 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}`);
}
}
}