@@ -732,36 +732,42 @@ function insertTableofContents(content) {
732732 let toc = ''
733733 const count = { }
734734 const slugger = title => title . toLowerCase ( ) . replace ( / / g, '-' ) . replace ( / - + / g, '-' ) . replace ( / [ ^ a - z A - Z - ] / g, '' )
735- let collapsedContentLevel = null
735+ let inPrivateSection = false
736736
737737 content . split ( '\n' ) . filter ( line => line . match ( / ^ \# / ) ) . map ( line => {
738738 const match = line . match ( / ^ ( \# + ) ( .* ) / )
739- if ( match ) {
739+
740+ if ( ! match ) { return }
741+
742+ // level 2 == section title (Usage, Overview, Methods, etc)
743+ // level 3 == method/event names; we'll only list public methods/events in the ToC
744+ // level 4 == examples; we'll ignore these in the ToC
740745 const level = match [ 1 ] . length
741- if ( level > 1 && level < 4 ) {
742- if ( collapsedContentLevel === level ) {
743- // we are back to the level we started the collapsed content, end the collapse
744- toc += ' ' + ' ' . repeat ( collapsedContentLevel ) + '</details>\n'
745- collapsedContentLevel = null
746- }
747746 const title = match [ 2 ]
748747 const slug = slugger ( title )
748+
749749 if ( count . hasOwnProperty ( slug ) ) {
750750 count [ slug ] += 1
751751 }
752752 else {
753753 count [ slug ] = 0
754754 }
755755 const link = '#' + slug + ( count [ slug ] ? `-${ count [ slug ] } ` : '' )
756- toc += ' ' + ' ' . repeat ( level - 1 ) + `- [${ title } ](${ link } )`
756+
757+ if ( level == 2 || level == 3 ) {
758+ if ( inPrivateSection ) {
759+ // we're currently in a private section and don't want to output private methods/events in ToC
760+ if ( level == 3 ) { return }
761+
762+ // we've dropped out of a private section, output methods as normal
763+ inPrivateSection = false
764+ }
765+
757766 if ( title === 'Private Methods' || title === 'Private Events' ) {
758- let anchor = title === 'Private Methods' ? 'private-methods-details' : 'private-events-details'
759- toc += '<details ontoggle="document.getElementById(\'' + anchor + '\').open=this.open"><summary>Show</summary>\n'
760- collapsedContentLevel = level
761- } else {
762- toc += '\n'
763- }
767+ inPrivateSection = true
764768 }
769+
770+ toc += ' ' . repeat ( level - 2 ) + `- [${ title } ](${ link } )\n`
765771 }
766772 } ) . join ( '\n' )
767773
0 commit comments