Skip to content

Commit 5e63d90

Browse files
committed
feat(print/list): start rewriting headings
1 parent 4958b89 commit 5e63d90

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

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

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { t } from "../../../services/i18n";
1313
import attribute_renderer from "../../../services/attribute_renderer";
1414
import froca from "../../../services/froca";
1515
import { RawHtmlBlock } from "../../react/RawHtml";
16+
import { escapeHtml } from "../../../services/utils";
1617

1718
export function ListView({ note, noteIds: unfilteredNoteIds, highlightedTokens }: ViewModeProps<{}>) {
1819
const [ isExpanded ] = useNoteLabelBoolean(note, "expanded");
@@ -41,7 +42,7 @@ interface NotesWithContent {
4142
content: string;
4243
}
4344

44-
export function ListPrintView({ note, noteIds: unfilteredNoteIds, highlightedTokens, onReady }: ViewModeProps<{}>) {
45+
export function ListPrintView({ note, noteIds: unfilteredNoteIds, onReady }: ViewModeProps<{}>) {
4546
const noteIds = useFilteredNoteIds(note, unfilteredNoteIds);
4647
const [ notesWithContent, setNotesWithContent ] = useState<NotesWithContent[]>();
4748

@@ -55,7 +56,24 @@ export function ListPrintView({ note, noteIds: unfilteredNoteIds, highlightedTok
5556
noChildrenList: true
5657
});
5758

58-
notesWithContent.push({ note, content: content.$renderedContent[0].innerHTML });
59+
const contentEl = content.$renderedContent[0];
60+
61+
// Create page title element
62+
const pageTitleEl = document.createElement("h1");
63+
pageTitleEl.textContent = note.title;
64+
contentEl.prepend(pageTitleEl);
65+
66+
// Rewrite heading tags to ensure proper hierarchy in print view.
67+
const headings = contentEl.querySelectorAll("h1, h2, h3, h4, h5, h6")
68+
for (const headingEl of headings) {
69+
const currentLevel = parseInt(headingEl.tagName.substring(1), 10);
70+
const newLevel = Math.min(currentLevel + 1, 6); // Shift down by 1, max to h6
71+
const newHeadingEl = document.createElement(`h${newLevel}`);
72+
newHeadingEl.innerHTML = headingEl.innerHTML;
73+
headingEl.replaceWith(newHeadingEl);
74+
}
75+
76+
notesWithContent.push({ note, content: contentEl.innerHTML });
5977

6078
if (note.hasChildren()) {
6179
const imageLinks = note.getRelations("imageLink");
@@ -87,7 +105,6 @@ export function ListPrintView({ note, noteIds: unfilteredNoteIds, highlightedTok
87105

88106
{notesWithContent?.map(({ note: childNote, content }) => (
89107
<section id={`note-${childNote.noteId}`} class="note">
90-
<h1>{childNote.title}</h1>
91108
<RawHtmlBlock html={content} />
92109
</section>
93110
))}

0 commit comments

Comments
 (0)