Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(toc): Support unnumbered headings #4871

Merged

Conversation

Cerallin
Copy link
Contributor

@Cerallin Cerallin commented Jan 19, 2022

What does it do?

This PR adds a new feature to hexo to control the numbering of headings by the data-toc-unnumbered attribute.

Using pandoc, code written in markdown like

### Title { data-toc-unnumbered=true }

will be rendered as

<h3 data-toc-unnumbered="true" id="title">Title</h3>

and finally unnumbered in TOC.

Screenshots

image

image

image

Pull request tasks

  • Add test cases for the changes.
  • Passed the CI test.

This PR should be merged after hexojs/hexo-util#269 merged and published with hexo-util.

Closes #4860.

@github-actions
Copy link

github-actions bot commented Jan 19, 2022

How to test

git clone -b feat/toc-support-unnumbered-headings https://github.com/Cerallin/hexo.git
cd hexo
npm install
npm test

@yoshinorin
Copy link
Member

@Cerallin

Now, I'm testing this PR with hexojs/hexo-util#269 in my machine.
My understanding, according to your explanation & hexojs/hexo-util#269 test code the below markdown...

### Title { data-toc-unnumbered=true }

will be reneder belows.

<h3 id="title" data-toc-unnumbered="true">Title</h3>

But, it can't.
Would you please explain how to add an attribute to markdown headings? Or, would you please see the demo source code to me?

Thank you :)

@yoshinorin yoshinorin marked this pull request as draft January 22, 2022 06:19
@Cerallin
Copy link
Contributor Author

@yoshinorin

This is because I am using hexo-renderer-pandoc.
You can also generate an HTML file directly with pandoc:

pandoc test.md -o test.html

Ref: https://pandoc.org/MANUAL.html#extension-header_attributes

@yoshinorin
Copy link
Member

Waiting for the release of hexo-util 2.6.0

@yoshinorin
Copy link
Member

@Cerallin
Sorry so late reply.
We merged hexo-util 2.6.0. Would you please rebase?

Thank you :)

@Cerallin Cerallin force-pushed the feat/toc-support-unnumbered-headings branch from 9c3d57a to e0b9a0c Compare March 6, 2022 12:22
@Cerallin
Copy link
Contributor Author

Cerallin commented Mar 6, 2022

Cherry-picked my commit. :)

@yoshinorin yoshinorin marked this pull request as ready for review March 6, 2022 13:51
Copy link
Member

@yoshinorin yoshinorin left a comment

Choose a reason for hiding this comment

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

LGTM.
Thank you :)

@yoshinorin yoshinorin merged commit 24d8c31 into hexojs:master Mar 6, 2022
yoshinorin added a commit to yoshinorin/site that referenced this pull request Mar 12, 2022
tomap pushed a commit to hexojs/site that referenced this pull request Mar 13, 2022
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: Support unnumbered titles
2 participants