Skip to content

Commit bbcc2f4

Browse files
committed
feat(print/list): rewrite headings while preserving depth
1 parent 5e63d90 commit bbcc2f4

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export function ListPrintView({ note, noteIds: unfilteredNoteIds, onReady }: Vie
5050
froca.getNotes(noteIds).then(async (notes) => {
5151
const notesWithContent: NotesWithContent[] = [];
5252

53-
async function processNote(note: FNote) {
53+
async function processNote(note: FNote, depth: number) {
5454
const content = await content_renderer.getRenderedContent(note, {
5555
trim: false,
5656
noChildrenList: true
@@ -67,7 +67,7 @@ export function ListPrintView({ note, noteIds: unfilteredNoteIds, onReady }: Vie
6767
const headings = contentEl.querySelectorAll("h1, h2, h3, h4, h5, h6")
6868
for (const headingEl of headings) {
6969
const currentLevel = parseInt(headingEl.tagName.substring(1), 10);
70-
const newLevel = Math.min(currentLevel + 1, 6); // Shift down by 1, max to h6
70+
const newLevel = Math.min(currentLevel + depth, 6);
7171
const newHeadingEl = document.createElement(`h${newLevel}`);
7272
newHeadingEl.innerHTML = headingEl.innerHTML;
7373
headingEl.replaceWith(newHeadingEl);
@@ -80,13 +80,13 @@ export function ListPrintView({ note, noteIds: unfilteredNoteIds, onReady }: Vie
8080
const childNotes = await note.getChildNotes();
8181
const filteredChildNotes = childNotes.filter((childNote) => !imageLinks.find((rel) => rel.value === childNote.noteId));
8282
for (const childNote of filteredChildNotes) {
83-
await processNote(childNote);
83+
await processNote(childNote, depth + 1);
8484
}
8585
}
8686
}
8787

8888
for (const note of notes) {
89-
await processNote(note);
89+
await processNote(note, 1);
9090
}
9191
setNotesWithContent(notesWithContent);
9292
});

0 commit comments

Comments
 (0)