File tree Expand file tree Collapse file tree 1 file changed +19
-8
lines changed Expand file tree Collapse file tree 1 file changed +19
-8
lines changed Original file line number Diff line number Diff line change @@ -59,20 +59,31 @@ const updateFunction = () => {
59
59
if ( activeLink ) activeLink . classList . add ( "active" ) ;
60
60
}
61
61
} ;
62
+ function getHeaderText ( header ) {
63
+ let text = header . textContent ;
64
+ if ( text === "" ) {
65
+ let sibling = header . nextSibling ;
66
+ let maxIterations = 100 ;
67
+ while ( sibling != null && maxIterations > 0 ) {
68
+ text += sibling . textContent ;
69
+ sibling = sibling . nextSibling ;
70
+ maxIterations -- ;
71
+ }
72
+ if ( maxIterations === 0 ) {
73
+ console . warn (
74
+ "Possible circular reference in DOM when extracting header text"
75
+ ) ;
76
+ }
77
+ }
78
+ return text ;
79
+ }
62
80
63
81
const onLoad = ( ) => {
64
82
const pagetoc = getPagetoc ( ) ;
65
83
var headers = [ ...document . getElementsByClassName ( "header" ) ] ;
66
84
headers . shift ( ) ;
67
85
headers . forEach ( ( header ) => {
68
- var text = header . textContent ;
69
- if ( text === "" ) {
70
- sibling = header . nextSibling
71
- while ( sibling != null ) {
72
- text += sibling . textContent ;
73
- sibling = sibling . nextSibling
74
- }
75
- }
86
+ const text = getHeaderText ( header ) ;
76
87
const link = Object . assign ( document . createElement ( "a" ) , {
77
88
textContent : text ,
78
89
href : header . href ,
You can’t perform that action at this time.
0 commit comments