Skip to content

Build your personal knowledge base with Trilium Notes

feat(print): allow custom CSS (closes #7608)

Elian Doran7a677cff5f63
diff --git a/apps/client/src/print.tsx b/apps/client/src/print.tsx
index 3dbdf1de07..88100c4cbe 100644
--- a/apps/client/src/print.tsx
+++ b/apps/client/src/print.tsx
@@ -70,6 +70,9 @@ function SingleNoteRenderer({ note, onReady }: RendererProps) {
});
})
);
+
+ // Check custom CSS.
+ await loadCustomCss(note);
}
load().then(() => requestAnimationFrame(onReady))
@@ -102,4 +105,17 @@ function Error404({ noteId }: { noteId: string }) {
)
}
+async function loadCustomCss(note: FNote) {
+ const printCssNotes = await note.getRelationTargets("printCss");
+
+ for (const printCssNote of printCssNotes) {
+ if (!printCssNote || (printCssNote.type !== "code" && printCssNote.mime !== "text/css")) continue;
+
+ const linkEl = document.createElement("link");
+ linkEl.href = `/api/notes/${printCssNote.noteId}/download`;
+ linkEl.rel = "stylesheet";
+ document.head.appendChild(linkEl);
+ }
+}
+
main();