From 7a677cff5f630a08eaf6a353499b445f05721c0b Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Fri, 7 Nov 2025 17:25:05 +0200 Subject: [PATCH] feat(print): allow custom CSS (closes #7608) --- apps/client/src/print.tsx | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/apps/client/src/print.tsx b/apps/client/src/print.tsx index 3dbdf1de0..88100c4cb 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();