From 5e63d9015f2e41cd2fd46ffc12c42126f6ebd4d4 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Thu, 20 Nov 2025 20:48:39 +0200 Subject: [PATCH] feat(print/list): start rewriting headings --- .../collections/legacy/ListOrGridView.tsx | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/apps/client/src/widgets/collections/legacy/ListOrGridView.tsx b/apps/client/src/widgets/collections/legacy/ListOrGridView.tsx index 2970e4e38..de81264d2 100644 --- a/apps/client/src/widgets/collections/legacy/ListOrGridView.tsx +++ b/apps/client/src/widgets/collections/legacy/ListOrGridView.tsx @@ -13,6 +13,7 @@ import { t } from "../../../services/i18n"; import attribute_renderer from "../../../services/attribute_renderer"; import froca from "../../../services/froca"; import { RawHtmlBlock } from "../../react/RawHtml"; +import { escapeHtml } from "../../../services/utils"; export function ListView({ note, noteIds: unfilteredNoteIds, highlightedTokens }: ViewModeProps<{}>) { const [ isExpanded ] = useNoteLabelBoolean(note, "expanded"); @@ -41,7 +42,7 @@ interface NotesWithContent { content: string; } -export function ListPrintView({ note, noteIds: unfilteredNoteIds, highlightedTokens, onReady }: ViewModeProps<{}>) { +export function ListPrintView({ note, noteIds: unfilteredNoteIds, onReady }: ViewModeProps<{}>) { const noteIds = useFilteredNoteIds(note, unfilteredNoteIds); const [ notesWithContent, setNotesWithContent ] = useState(); @@ -55,7 +56,24 @@ export function ListPrintView({ note, noteIds: unfilteredNoteIds, highlightedTok noChildrenList: true }); - notesWithContent.push({ note, content: content.$renderedContent[0].innerHTML }); + const contentEl = content.$renderedContent[0]; + + // Create page title element + const pageTitleEl = document.createElement("h1"); + pageTitleEl.textContent = note.title; + contentEl.prepend(pageTitleEl); + + // Rewrite heading tags to ensure proper hierarchy in print view. + const headings = contentEl.querySelectorAll("h1, h2, h3, h4, h5, h6") + for (const headingEl of headings) { + const currentLevel = parseInt(headingEl.tagName.substring(1), 10); + const newLevel = Math.min(currentLevel + 1, 6); // Shift down by 1, max to h6 + const newHeadingEl = document.createElement(`h${newLevel}`); + newHeadingEl.innerHTML = headingEl.innerHTML; + headingEl.replaceWith(newHeadingEl); + } + + notesWithContent.push({ note, content: contentEl.innerHTML }); if (note.hasChildren()) { const imageLinks = note.getRelations("imageLink"); @@ -87,7 +105,6 @@ export function ListPrintView({ note, noteIds: unfilteredNoteIds, highlightedTok {notesWithContent?.map(({ note: childNote, content }) => (
-

{childNote.title}

))}