-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
TOC (Table of contents) helper #408
Comments
commit: 3efb980 |
Cool. Maybe add one more option:
|
Can someone provide an example of how to use this? |
I'd like to be able to insert [toc] into my Markdown to display a TOC, which I can do using a filter, but how can I access this helper from my script? |
Put the following in the theme:
And this helper will scan all headers in the content and generate a table of contents. |
Hi, I am using Hexo 2.6.1 and landscape theme, and try to add a toc into my post. Adding
into
shows the TOC. However, there are extra numbers before each line of TOC. Thanks! |
@fwz See this pull request. |
@NicholasTD07 If so, is it possible to set the |
Thanks! |
<%- toc(page.content, {list_number: false}) %> |
Any way to use this like I've tried to reuse hexo.extend.filter.register('post', function(data) {
data.content = data.content.replace(/<!-{2,} *toc *-{2,}>/, hexo.plugins.helper.toc.tocHelper(data.content));
return data;
}); |
@kuanyui ,you can only call this helper in your theme template files(.ejs). |
But I don't want to add the TOC at a fix position. |
If so, then don't use this helper. There are many other jQuery plugins that are more flexible and suitable for your demand e.g. http://fuelyourcoding.com/scripts/toc/ |
@JiantaoFu set |
Could toc function provide the depth option? I think this option could make the page more simple and eligant. |
I saw that the tocHelper is registered in the Hexo.js code with @kuanyui: Currently I am importing the const tocHelper = require('hexo/lib/plugins/helper/toc');
const toc = tocHelper(html, { max_depth: 2 }); |
Usage
<%- toc(str, [options]) %>
The text was updated successfully, but these errors were encountered: