File tree Expand file tree Collapse file tree 2 files changed +17
-3
lines changed Expand file tree Collapse file tree 2 files changed +17
-3
lines changed Original file line number Diff line number Diff line change @@ -1015,14 +1015,19 @@ export function renderTOC (view) {
10151015 target . html ( '' )
10161016 /* eslint-disable no-unused-vars */
10171017
1018+ const specificDepth = parseInt ( toc . data ( 'toc-depth' ) )
1019+
10181020 var tocOptions = md . meta . toc || { }
1019- var maxLevel = ( typeof tocOptions . maxLevel === 'number' && tocOptions . maxLevel > 0 ) ? tocOptions . maxLevel : window . defaultTocDepth
1021+ var yamlMaxDepth = ( typeof tocOptions . maxLevel === 'number' && tocOptions . maxLevel > 0 ) ? tocOptions . maxLevel : window . defaultTocDepth
1022+
1023+ var maxLevel = specificDepth || yamlMaxDepth
10201024
10211025 const TOC = new window . Toc ( 'doc' , {
10221026 level : maxLevel ,
10231027 top : - 1 ,
10241028 class : 'toc' ,
10251029 targetId : id ,
1030+ data : { tocDepth : specificDepth } ,
10261031 process : getHeaderContent
10271032 } )
10281033 /* eslint-enable no-unused-vars */
@@ -1268,9 +1273,12 @@ const gistPlugin = new Plugin(
12681273// TOC
12691274const tocPlugin = new Plugin (
12701275 // regexp to match
1271- / ^ \[ T O C \] $ / i,
1276+ / ^ \[ T O C ( | \s * m a x L e v e l = \d + ? ) \] $ / i,
12721277
1273- ( match , utils ) => '<div class="toc"></div>'
1278+ ( match , utils ) => {
1279+ const tocDepth = match [ 1 ] . split ( / [ ? & = ] + / ) [ 1 ]
1280+ return `<div class="toc" data-toc-depth="${ tocDepth } "></div>`
1281+ }
12741282)
12751283// slideshare
12761284const slidesharePlugin = new Plugin (
Original file line number Diff line number Diff line change 22/**
33 * md-toc.js v1.0.2
44 * https://github.com/yijian166/md-toc.js
5+ *
6+ * Adapted to accept data attributes
57 */
68
79( function ( window ) {
1517 this . tocTop = parseInt ( options . top ) || 0
1618 this . elChilds = this . el . children
1719 this . process = options [ 'process' ]
20+ this . data = options . data || { }
1821 if ( ! this . elChilds . length ) return
1922 this . _init ( )
2023 }
123126 this . toc = document . createElement ( 'div' )
124127 this . toc . innerHTML = this . tocContent
125128 this . toc . setAttribute ( 'class' , this . tocClass )
129+ if ( this . data . tocDepth ) {
130+ this . toc . dataset . tocDepth = this . data . tocDepth
131+ }
126132 if ( ! this . options . targetId ) {
127133 this . el . appendChild ( this . toc )
128134 } else {
You can’t perform that action at this time.
0 commit comments