@@ -12,7 +12,7 @@ const indentLevels = {
12
12
* H1, H2, and H3 elements.
13
13
*/
14
14
export const getPageTableOfContents = ( page , recordMap ) => {
15
- const contents = ( page . content ?? [ ] )
15
+ const contents = page . content ?? [ ]
16
16
const toc = getBlockHeader ( contents , recordMap )
17
17
const indentLevelStack = [
18
18
{
@@ -69,20 +69,28 @@ function getBlockHeader(contents, recordMap, toc) {
69
69
continue
70
70
}
71
71
const { type } = block
72
- if ( type . indexOf ( 'header' ) >= 0 ) {
73
- const existed = toc . find ( e => e . id === blockId )
74
- if ( ! existed ) {
75
- toc . push ( {
76
- id : blockId ,
77
- type,
78
- text : getTextContent ( block . properties ?. title ) ,
79
- indentLevel : indentLevels [ type ]
80
- } )
81
- }
82
- }
83
-
84
72
if ( block . content ?. length > 0 ) {
85
73
getBlockHeader ( block . content , recordMap , toc )
74
+ } else {
75
+ if ( type . indexOf ( 'header' ) >= 0 ) {
76
+ const existed = toc . find ( e => e . id === blockId )
77
+ if ( ! existed ) {
78
+ toc . push ( {
79
+ id : blockId ,
80
+ type,
81
+ text : getTextContent ( block . properties ?. title ) ,
82
+ indentLevel : indentLevels [ type ]
83
+ } )
84
+ }
85
+ } else if ( type === 'transclusion_reference' ) {
86
+ getBlockHeader (
87
+ [ block . format . transclusion_reference_pointer . id ] ,
88
+ recordMap ,
89
+ toc
90
+ )
91
+ } else if ( type === 'transclusion_container' ) {
92
+ getBlockHeader ( block . content , recordMap , toc )
93
+ }
86
94
}
87
95
}
88
96
0 commit comments