Bin
2025-12-16 971a2a12c03b74dd2d7d668b9dbc599f5131bcaf
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>`;
  };
};