diff --git a/lib/plugins/helper/toc.js b/lib/plugins/helper/toc.js index 4eb5093e8f..4e55c1fd44 100644 --- a/lib/plugins/helper/toc.js +++ b/lib/plugins/helper/toc.js @@ -4,12 +4,13 @@ const { tocObj } = require('hexo-util'); function tocHelper(str, options = {}) { options = Object.assign({ + min_depth: 1, max_depth: 6, class: 'toc', list_number: true }, options); - const data = tocObj(str, { max_depth: options.max_depth }); + const data = tocObj(str, { min_depth: options.min_depth, max_depth: options.max_depth }); if (!data.length) return ''; diff --git a/test/scripts/helpers/toc.js b/test/scripts/helpers/toc.js index 8d5f9fcb56..61f0525cce 100644 --- a/test/scripts/helpers/toc.js +++ b/test/scripts/helpers/toc.js @@ -311,4 +311,54 @@ describe('toc', () => { toc(html, { max_depth: 2 }).should.eql(expected); }); + + it('min_depth', () => { + const className = 'toc'; + const expected = [ + '
    ', + '
  1. ', + '', + '1. ', + 'Title 1.1', + '', + '
      ', + '
    1. ', + '', + '1.1. ', + 'Title 1.1.1', + '', + '
    2. ', + '
    ', + '
  2. ', + '
  3. ', + '', + '2. ', + 'Title 1.2', + '', + '
  4. ', + '
  5. ', + '', + '3. ', + 'Title 1.3', + '', + '
      ', + '
    1. ', + '', + '3.1. ', + 'Title 1.3.1', + '', + '
    2. ', + '
    ', + '
  6. ', + '
  7. ', + '', + '4. ', + 'Title 2.1', + '', + '
  8. ', + '
' + ].join(''); + + toc(html, { min_depth: 2 }).should.eql(expected); + }); });