Skip to content

add min_depth to toc() helper#3929

Closed
noraj wants to merge 2 commits into
hexojs:masterfrom
noraj:toc_min_depth
Closed

add min_depth to toc() helper#3929
noraj wants to merge 2 commits into
hexojs:masterfrom
noraj:toc_min_depth

Conversation

@noraj

@noraj noraj commented Dec 11, 2019

Copy link
Copy Markdown
Contributor

What does it do?

fix #3288

How to test

git clone -b BRANCH https://github.com/noraj/hexo.git
cd hexo
git checkout toc_min_depth
npm install
npm test
npm run eslint

Screenshots

Pull request tasks

  • Add test cases for the changes. [WIP] tests for toc plugin seem complex, so I begin to write them but I wasn't able to finish.
  • Passed the CI test. No, because tests are not finished.

@coveralls

Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.0008%) to 97.136% when pulling dad6e85 on noraj:toc_min_depth into 8677963 on hexojs:master.

Comment thread lib/plugins/helper/toc.js
const $ = cheerio.load(str);
const headingsMaxDepth = Object.prototype.hasOwnProperty.call(options, 'max_depth') ? options.max_depth : 6;
const headingsSelector = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6'].slice(0, headingsMaxDepth).join(',');
const headingsMinDepth = Object.prototype.hasOwnProperty.call(options, 'min_depth') ? options.min_depth : 1;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is better to use Object.assign to handle multiple default config.

@curbengh

Copy link
Copy Markdown
Contributor

Is this compatible with #3850?

@SukkaW

SukkaW commented Dec 12, 2019

Copy link
Copy Markdown
Member

@curbengh I could bring up #3850 (with hexo-util's tocObj()) over this PR then.

@curbengh

Copy link
Copy Markdown
Contributor

My understanding is that tocObj() implemented min_depth, so this PR should be superseded by #3850.

@SukkaW SukkaW closed this in #3997 Dec 21, 2019
@noraj noraj deleted the toc_min_depth branch December 21, 2019 17:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TOC helper: add min_depth

4 participants