mirror of
https://github.com/zadam/trilium.git
synced 2025-11-21 08:04:24 +01:00
refactor(print/list): extract into functions
This commit is contained in:
parent
c17df24a19
commit
89a83a625b
@ -27,20 +27,8 @@ export function ListPrintView({ note, noteIds: unfilteredNoteIds, onReady }: Vie
|
|||||||
|
|
||||||
const contentEl = content.$renderedContent[0];
|
const contentEl = content.$renderedContent[0];
|
||||||
|
|
||||||
// Create page title element
|
insertPageTitle(contentEl, note.title);
|
||||||
const pageTitleEl = document.createElement("h1");
|
rewriteHeadings(contentEl, depth);
|
||||||
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 + depth, 6);
|
|
||||||
const newHeadingEl = document.createElement(`h${newLevel}`);
|
|
||||||
newHeadingEl.innerHTML = headingEl.innerHTML;
|
|
||||||
headingEl.replaceWith(newHeadingEl);
|
|
||||||
}
|
|
||||||
|
|
||||||
notesWithContent.push({ note, content: contentEl.innerHTML });
|
notesWithContent.push({ note, content: contentEl.innerHTML });
|
||||||
|
|
||||||
@ -81,3 +69,20 @@ export function ListPrintView({ note, noteIds: unfilteredNoteIds, onReady }: Vie
|
|||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function insertPageTitle(contentEl: HTMLElement, title: string) {
|
||||||
|
const pageTitleEl = document.createElement("h1");
|
||||||
|
pageTitleEl.textContent = title;
|
||||||
|
contentEl.prepend(pageTitleEl);
|
||||||
|
}
|
||||||
|
|
||||||
|
function rewriteHeadings(contentEl: HTMLElement, depth: number) {
|
||||||
|
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 + depth, 6);
|
||||||
|
const newHeadingEl = document.createElement(`h${newLevel}`);
|
||||||
|
newHeadingEl.innerHTML = headingEl.innerHTML;
|
||||||
|
headingEl.replaceWith(newHeadingEl);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user