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) {
1015
1015
target . html ( '' )
1016
1016
/* eslint-disable no-unused-vars */
1017
1017
1018
+ const specificDepth = parseInt ( toc . data ( 'toc-depth' ) )
1019
+
1018
1020
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
1020
1024
1021
1025
const TOC = new window . Toc ( 'doc' , {
1022
1026
level : maxLevel ,
1023
1027
top : - 1 ,
1024
1028
class : 'toc' ,
1025
1029
targetId : id ,
1030
+ data : { tocDepth : specificDepth } ,
1026
1031
process : getHeaderContent
1027
1032
} )
1028
1033
/* eslint-enable no-unused-vars */
@@ -1268,9 +1273,12 @@ const gistPlugin = new Plugin(
1268
1273
// TOC
1269
1274
const tocPlugin = new Plugin (
1270
1275
// regexp to match
1271
- / ^ \[ T O C \] $ / i,
1276
+ / ^ \[ T O C ( | \s * m a x L e v e l = \d + ? ) \] $ / i,
1272
1277
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
+ }
1274
1282
)
1275
1283
// slideshare
1276
1284
const slidesharePlugin = new Plugin (
Original file line number Diff line number Diff line change 2
2
/**
3
3
* md-toc.js v1.0.2
4
4
* https://github.com/yijian166/md-toc.js
5
+ *
6
+ * Adapted to accept data attributes
5
7
*/
6
8
7
9
( function ( window ) {
15
17
this . tocTop = parseInt ( options . top ) || 0
16
18
this . elChilds = this . el . children
17
19
this . process = options [ 'process' ]
20
+ this . data = options . data || { }
18
21
if ( ! this . elChilds . length ) return
19
22
this . _init ( )
20
23
}
123
126
this . toc = document . createElement ( 'div' )
124
127
this . toc . innerHTML = this . tocContent
125
128
this . toc . setAttribute ( 'class' , this . tocClass )
129
+ if ( this . data . tocDepth ) {
130
+ this . toc . dataset . tocDepth = this . data . tocDepth
131
+ }
126
132
if ( ! this . options . targetId ) {
127
133
this . el . appendChild ( this . toc )
128
134
} else {
You can’t perform that action at this time.
0 commit comments