File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -341,6 +341,7 @@ function generateToc(id) {
341341 'level' : 3 ,
342342 'top' : - 1 ,
343343 'class' : 'toc' ,
344+ 'ulClass' : 'nav' ,
344345 'targetId' : id
345346 } ) ;
346347 if ( target . text ( ) == 'undefined' )
@@ -460,6 +461,26 @@ function deduplicatedHeaderId(view) {
460461 }
461462}
462463
464+ function renderTOC ( view ) {
465+ var tocs = view . find ( '.toc' ) . toArray ( ) ;
466+ for ( var i = 0 ; i < tocs . length ; i ++ ) {
467+ var toc = $ ( tocs [ i ] ) ;
468+ var id = 'toc' + i ;
469+ toc . attr ( 'id' , id ) ;
470+ var target = $ ( '#' + id ) ;
471+ target . html ( '' ) ;
472+ new Toc ( 'doc' , {
473+ 'level' : 3 ,
474+ 'top' : - 1 ,
475+ 'class' : 'toc' ,
476+ 'targetId' : id
477+ } ) ;
478+ if ( target . text ( ) == 'undefined' )
479+ target . html ( '' ) ;
480+ target . replaceWith ( target . html ( ) ) ;
481+ }
482+ }
483+
463484function scrollToHash ( ) {
464485 var hash = location . hash ;
465486 location . hash = "" ;
@@ -623,7 +644,18 @@ var mathjaxPlugin = new Plugin(
623644 return '<span class="mathjax raw">' + match [ 0 ] + '</span>' ;
624645 }
625646) ;
647+ //TOC
648+ var tocPlugin = new Plugin (
649+ // regexp to match
650+ / ^ \[ T O C \] $ / ,
651+
652+ // this function will be called when something matches
653+ function ( match , utils ) {
654+ return '<div class="toc"></div>' ;
655+ }
656+ ) ;
626657md . use ( youtubePlugin ) ;
627658md . use ( vimeoPlugin ) ;
628659md . use ( gistPlugin ) ;
629- md . use ( mathjaxPlugin ) ;
660+ md . use ( mathjaxPlugin ) ;
661+ md . use ( tocPlugin ) ;
Original file line number Diff line number Diff line change @@ -86,6 +86,10 @@ var supportReferrals = [
8686 {
8787 text : '' ,
8888 search : '![]()'
89+ } ,
90+ {
91+ text : '[TOC]' ,
92+ search : '[]'
8993 }
9094] ;
9195var supportExternals = [
@@ -1876,6 +1880,7 @@ function updateViewInner() {
18761880 finishView ( ui . area . view ) ;
18771881 autoLinkify ( ui . area . view ) ;
18781882 deduplicatedHeaderId ( ui . area . view ) ;
1883+ renderTOC ( ui . area . view ) ;
18791884 generateToc ( 'toc' ) ;
18801885 generateToc ( 'toc-affix' ) ;
18811886 generateScrollspy ( ) ;
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ $(document.body).show();
66finishView ( markdown ) ;
77autoLinkify ( markdown ) ;
88deduplicatedHeaderId ( markdown ) ;
9+ renderTOC ( markdown ) ;
910generateToc ( 'toc' ) ;
1011generateToc ( 'toc-affix' ) ;
1112smoothHashScroll ( ) ;
Original file line number Diff line number Diff line change 1010 this . options = options || { } ;
1111 this . tocLevel = parseInt ( options . level ) || 0 ;
1212 this . tocClass = options [ 'class' ] || 'toc' ;
13+ this . ulClass = options [ 'ulClass' ] ;
1314 this . tocTop = parseInt ( options . top ) || 0 ;
1415 this . elChilds = this . el . children ;
1516 if ( ! this . elChilds . length ) return ;
8081 this . _tempLists . length = this . _tempLists . length - y ;
8182 } else {
8283 this . _tempLists . push ( this . _elTitleElement ) ;
83- this . tocContent += '<ul class="nav">' ;
84+ if ( this . ulClass )
85+ this . tocContent += '<ul class="' + this . ulClass + '">' ;
86+ else
87+ this . tocContent += '<ul>' ;
8488 }
8589 } else {
8690 this . tocContent += '</li>' ;
9397 }
9498 }
9599 }
96- this . tocContent = '<ul class="nav">' + this . tocContent + '</ul>' ;
100+ if ( this . ulClass )
101+ this . tocContent = '<ul class="' + this . ulClass + '">' + this . tocContent + '</ul>' ;
102+ else
103+ this . tocContent = '<ul>' + this . tocContent + '</ul>' ;
97104 } ;
98105
99106 Toc . prototype . _showToc = function ( ) {
You can’t perform that action at this time.
0 commit comments