@@ -10,7 +10,7 @@ export async function openOrCreateNote(app: App, file: TFile, toc: string) {
1010 `---\nbookname: "${ file . basename } .${ file . extension } "\n---\n\n` + toc
1111 ) ;
1212 }
13- const leaf = app . workspace . getMostRecentLeaf ( )
13+ const leaf = app . workspace . getMostRecentLeaf ( ) ;
1414 if ( leaf instanceof WorkspaceLeaf ) {
1515 const fileLeaf = app . workspace . createLeafBySplit ( leaf ) ;
1616 await fileLeaf . openFile ( noteFile as TFile , { active : true } ) ;
@@ -20,40 +20,40 @@ export async function openOrCreateNote(app: App, file: TFile, toc: string) {
2020export function getEpubTocMd ( rawToc : any ) {
2121 function dfs ( node : { label : string ; subitems : any ; } , output : any [ ] , depth : number ) {
2222 if ( ! node ) return ;
23- const cleanedLabel = node . label . replace ( / \u0000 / g, '' ) . trim ( )
24- output . push ( "#" . repeat ( depth ) + " " + cleanedLabel )
23+ const cleanedLabel = node . label . replace ( / \u0000 / g, '' ) . trim ( ) ;
24+ output . push ( "#" . repeat ( depth ) + " " + cleanedLabel ) ;
2525 for ( let sub of node . subitems ) {
26- dfs ( sub , output , depth + 1 )
26+ dfs ( sub , output , depth + 1 ) ;
2727 }
2828 }
2929
3030 if ( ! rawToc ) return "" ;
31- const output : any [ ] = [ ]
31+ const output : any [ ] = [ ] ;
3232 for ( let sub of rawToc ) {
33- dfs ( sub , output , 1 )
33+ dfs ( sub , output , 1 ) ;
3434 }
35- return output . join ( "\n\n" )
35+ return output . join ( "\n\n" ) ;
3636}
3737
3838export async function getPdfTocMd ( file : TFile ) {
39- const pdfjsLib = await loadPdfJs ( )
40- const content = await this . app . vault . adapter . readBinary ( file . path ) ;
41- const pdf = await pdfjsLib . getDocument ( new Uint8Array ( content ) ) . promise
42- const rawToc = await pdf . getOutline ( )
39+ const pdfjsLib = await loadPdfJs ( ) ;
40+ const content = await this . app . vault . readBinary ( file . path ) ;
41+ const pdf = await pdfjsLib . getDocument ( new Uint8Array ( content ) ) . promise ;
42+ const rawToc = await pdf . getOutline ( ) ;
4343
4444 function dfs ( node : { title : string ; items : any ; } , output : any [ ] , depth : number ) {
4545 if ( ! node ) return ;
46- const cleanedLabel = node . title . replace ( / \u0000 / g, '' ) . trim ( )
47- output . push ( "#" . repeat ( depth ) + " " + cleanedLabel )
46+ const cleanedLabel = node . title . replace ( / \u0000 / g, '' ) . trim ( ) ;
47+ output . push ( "#" . repeat ( depth ) + " " + cleanedLabel ) ;
4848 for ( let sub of node . items ) {
49- dfs ( sub , output , depth + 1 )
49+ dfs ( sub , output , depth + 1 ) ;
5050 }
5151 }
5252
5353 if ( ! rawToc ) return "" ;
54- const output : any [ ] = [ ]
54+ const output : any [ ] = [ ] ;
5555 for ( let sub of rawToc ) {
56- dfs ( sub , output , 1 )
56+ dfs ( sub , output , 1 ) ;
5757 }
58- return output . join ( "\n\n" )
58+ return output . join ( "\n\n" ) ;
5959}
0 commit comments