Bin
2025-12-17 05a69820e0c402b0b33c063d3b922f0a0571cbbb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
const { tocObj } = require('hexo-util');
 
module.exports = function () {
  return function tableOfContent(str, options = {}) {
 
      options = Object.assign({
        min_depth: 1,
        max_depth: 6,
      }, options);
    
      const data = tocObj(str, { min_depth: options.min_depth, max_depth: options.max_depth });
 
    
      if (!data.length) return '';
    
      let html = '';
 
      data.forEach(item => {
        html += `<li class="toc-list-level-${item.level}"><a href="#${item.id}">${item.text}</a></li>`
      });
 
      return `<ol class="toc-list">${html}</ol>`;
  };
};