toc.js // content of node_modules/hexo/lib/plugins/helper/toc.js'use strict';var cheerio;function tocHelper(str, options) { options = options || {}; if (!cheerio) cheerio = require('cheerio'); var $ = cheerio.load(str); var headingsMaxDepth
// content of node_modules/hexo/lib/plugins/helper/toc.js 'use strict'; var cheerio; function tocHelper(str, options) { options = options || {}; if (!cheerio) cheerio = require('cheerio'); var $ = cheerio.load(str); var headingsMaxDepth = options.hasOwnProperty('max_depth') ? options.max_depth : 6; var headingsSelector = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6'].slice(0, headingsMaxDepth).join(','); var headings = $(headingsSelector); if (!headings.length) return ''; var className = options.class || 'toc'; var listNumber = options.hasOwnProperty('list_number') ? options.list_number : true; var result = 'tocPatch.js'; var lastNumber = [0, 0, 0, 0, 0, 0]; var firstLevel = 0; var lastLevel = 0; var i = 0; headings.each(function () { var level = +this.name[1]; var id = $(this).attr('id'); var text = $(this).html(); lastNumber[level - 1]++; for (i = level; i <= 5; i++) { lastNumber[i] = 0; } if (firstLevel) { for (i = level; i < lastLevel; i++) { result += '
'; } if (level > lastLevel) { result += ''; } else { result += ''; } } else { firstLevel = level; } result += '
'; } return result; } module.exports = tocHelper;- '; result += ''; if (listNumber) { result += ''; for (i = firstLevel - 1; i < level; i++) { result += lastNumber[i] + '.'; } result += ' '; } result += '' + text + ''; lastLevel = level; }); for (i = firstLevel - 1; i < lastLevel; i++) { result += '
// content of /script/tocPatch.js 'use strict'; var stripHTML = require('hexo-util').stripHTML; var cheerio; function tocHelper(str, options) { options = options || {}; if (!cheerio) cheerio = require('cheerio'); var $ = cheerio.load(str); var headingsMaxDepth = options.hasOwnProperty('max_depth') ? options.max_depth : 6; var headingsSelector = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6'].slice(0, headingsMaxDepth).join(','); var headings = $(headingsSelector); if (!headings.length) return ''; var className = options.class || 'toc'; var listNumber = options.hasOwnProperty('list_number') ? options.list_number : true; var result = ''; var lastNumber = [0, 0, 0, 0, 0, 0]; var firstLevel = 0; var lastLevel = 0; var i = 0; headings.each(function () { var level = +this.name[1]; var id = $(this).attr('id'); var text = $(this).html(); lastNumber[level - 1]++; for (i = level; i <= 5; i++) { lastNumber[i] = 0; } if (firstLevel) { for (i = level; i < lastLevel; i++) { result += '
'; } if (level > lastLevel) { result += ''; } else { result += ''; } } else { firstLevel = level; } result += '
'; } return result; } hexo.extend.helper.register('toc', tocHelper);- '; result += ''; if (listNumber) { result += ''; for (i = firstLevel - 1; i < level; i++) { result += lastNumber[i] + '.'; } result += ' '; } result += '' + stripHTML(text) + ''; lastLevel = level; }); for (i = firstLevel - 1; i < lastLevel; i++) { result += '