@@ -27,20 +27,8 @@ export function ListPrintView({ note, noteIds: unfilteredNoteIds, onReady }: Vie
2727
2828 const contentEl = content . $renderedContent [ 0 ] ;
2929
30- // Create page title element
31- const pageTitleEl = document . createElement ( "h1" ) ;
32- pageTitleEl . textContent = note . title ;
33- contentEl . prepend ( pageTitleEl ) ;
34-
35- // Rewrite heading tags to ensure proper hierarchy in print view.
36- const headings = contentEl . querySelectorAll ( "h1, h2, h3, h4, h5, h6" )
37- for ( const headingEl of headings ) {
38- const currentLevel = parseInt ( headingEl . tagName . substring ( 1 ) , 10 ) ;
39- const newLevel = Math . min ( currentLevel + depth , 6 ) ;
40- const newHeadingEl = document . createElement ( `h${ newLevel } ` ) ;
41- newHeadingEl . innerHTML = headingEl . innerHTML ;
42- headingEl . replaceWith ( newHeadingEl ) ;
43- }
30+ insertPageTitle ( contentEl , note . title ) ;
31+ rewriteHeadings ( contentEl , depth ) ;
4432
4533 notesWithContent . push ( { note, content : contentEl . innerHTML } ) ;
4634
@@ -81,3 +69,20 @@ export function ListPrintView({ note, noteIds: unfilteredNoteIds, onReady }: Vie
8169 </ div >
8270 ) ;
8371}
72+
73+ function insertPageTitle ( contentEl : HTMLElement , title : string ) {
74+ const pageTitleEl = document . createElement ( "h1" ) ;
75+ pageTitleEl . textContent = title ;
76+ contentEl . prepend ( pageTitleEl ) ;
77+ }
78+
79+ function rewriteHeadings ( contentEl : HTMLElement , depth : number ) {
80+ const headings = contentEl . querySelectorAll ( "h1, h2, h3, h4, h5, h6" )
81+ for ( const headingEl of headings ) {
82+ const currentLevel = parseInt ( headingEl . tagName . substring ( 1 ) , 10 ) ;
83+ const newLevel = Math . min ( currentLevel + depth , 6 ) ;
84+ const newHeadingEl = document . createElement ( `h${ newLevel } ` ) ;
85+ newHeadingEl . innerHTML = headingEl . innerHTML ;
86+ headingEl . replaceWith ( newHeadingEl ) ;
87+ }
88+ }
0 commit comments