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

Closed
tommy351 opened this Issue Dec 28, 2013 · 18 comments

Comments

10 participants
@tommy351
Member

tommy351 commented Dec 28, 2013

Usage

<%- toc(str, [options]) %>
  • str - Input string
  • options - Options
    • class - Class name
    • list_number - Display list number
@tommy351

This comment has been minimized.

Show comment
Hide comment
@tommy351

tommy351 Dec 29, 2013

Member

commit: 3efb980

Member

tommy351 commented Dec 29, 2013

commit: 3efb980

@tommy351 tommy351 closed this Dec 29, 2013

@wzpan

This comment has been minimized.

Show comment
Hide comment
@wzpan

wzpan Dec 31, 2013

Member

Cool. Maybe add one more option:

  • options - Options
    • class - Class name
    • list_number - Display list number
    • depth - the deepest heading level to be included.
Member

wzpan commented Dec 31, 2013

Cool. Maybe add one more option:

  • options - Options
    • class - Class name
    • list_number - Display list number
    • depth - the deepest heading level to be included.
@aexmachina

This comment has been minimized.

Show comment
Hide comment
@aexmachina

aexmachina Jan 8, 2014

Contributor

Can someone provide an example of how to use this?

Contributor

aexmachina commented Jan 8, 2014

Can someone provide an example of how to use this?

@aexmachina

This comment has been minimized.

Show comment
Hide comment
@aexmachina

aexmachina Jan 8, 2014

Contributor

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?

Contributor

aexmachina commented Jan 8, 2014

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?

@tommy351

This comment has been minimized.

Show comment
Hide comment
@tommy351

tommy351 Jan 8, 2014

Member

Put the following in the theme:

<%- toc(page.content) %>

And this helper will scan all headers in the content and generate a table of contents.

Member

tommy351 commented Jan 8, 2014

Put the following in the theme:

<%- toc(page.content) %>

And this helper will scan all headers in the content and generate a table of contents.

@fwz

This comment has been minimized.

Show comment
Hide comment
@fwz

fwz Jul 8, 2014

Hi, I am using Hexo 2.6.1 and landscape theme, and try to add a toc into my post.

Adding

<%- toc(page.content) %>

into themes/landscape/layout/_partial/article.ejs doesn't work. but adding

<%- toc(post.content) %>

shows the TOC.

However, there are extra numbers before each line of TOC.
I attach the HTML here: http://jsfiddle.net/de8a8/
Could anyone please take a look? how could I remove that number?

Thanks!

fwz commented Jul 8, 2014

Hi, I am using Hexo 2.6.1 and landscape theme, and try to add a toc into my post.

Adding

<%- toc(page.content) %>

into themes/landscape/layout/_partial/article.ejs doesn't work. but adding

<%- toc(post.content) %>

shows the TOC.

However, there are extra numbers before each line of TOC.
I attach the HTML here: http://jsfiddle.net/de8a8/
Could anyone please take a look? how could I remove that number?

Thanks!

@NicholasTD07

This comment has been minimized.

Show comment
Hide comment
@NicholasTD07

NicholasTD07 Aug 10, 2014

Contributor

@fwz See this pull request.

Contributor

NicholasTD07 commented Aug 10, 2014

@fwz See this pull request.

@fwz

This comment has been minimized.

Show comment
Hide comment
@fwz

fwz Aug 30, 2014

@NicholasTD07
Thanks. Are you referring to 3efb980 ?

If so, is it possible to set the list_number as false by configuration?

fwz commented Aug 30, 2014

@NicholasTD07
Thanks. Are you referring to 3efb980 ?

If so, is it possible to set the list_number as false by configuration?

@NicholasTD07

This comment has been minimized.

Show comment
Hide comment
@NicholasTD07

NicholasTD07 Aug 31, 2014

Contributor

@fwz Sorry, this one:

#780

Contributor

NicholasTD07 commented Aug 31, 2014

@fwz Sorry, this one:

#780

@fwz

This comment has been minimized.

Show comment
Hide comment
@fwz

fwz commented Aug 31, 2014

@NicholasTD07

Thanks!

@yantze

This comment has been minimized.

Show comment
Hide comment
@yantze

yantze Nov 16, 2014

<%- toc(page.content, {list_number: false}) %>

yantze commented Nov 16, 2014

<%- toc(page.content, {list_number: false}) %>

@kuanyui

This comment has been minimized.

Show comment
Hide comment
@kuanyui

kuanyui Mar 8, 2015

Any way to use this like <!-- toc --> in article ? Because I tend to place the TOC at exactly where I want in different article.

I've tried to reuse tocHelper(), but cannot find a way to call the function... (Sorry, I'm not familiar with Node.js...):

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 commented Mar 8, 2015

Any way to use this like <!-- toc --> in article ? Because I tend to place the TOC at exactly where I want in different article.

I've tried to reuse tocHelper(), but cannot find a way to call the function... (Sorry, I'm not familiar with Node.js...):

hexo.extend.filter.register('post', function(data) {
    data.content = data.content.replace(/<!-{2,} *toc *-{2,}>/, hexo.plugins.helper.toc.tocHelper(data.content));
    return data;
});
@wzpan

This comment has been minimized.

Show comment
Hide comment
@wzpan

wzpan Mar 9, 2015

Member

@kuanyui ,you can only call this helper in your theme template files(.ejs).

Member

wzpan commented Mar 9, 2015

@kuanyui ,you can only call this helper in your theme template files(.ejs).

@kuanyui

This comment has been minimized.

Show comment
Hide comment
@kuanyui

kuanyui Mar 9, 2015

But I don't want to add the TOC at a fix position.
For example, sometimes I insert the TOC after preamble, sometimes before.

kuanyui commented Mar 9, 2015

But I don't want to add the TOC at a fix position.
For example, sometimes I insert the TOC after preamble, sometimes before.

@wzpan

This comment has been minimized.

Show comment
Hide comment
@wzpan

wzpan Mar 10, 2015

Member

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/

Member

wzpan commented Mar 10, 2015

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

This comment has been minimized.

Show comment
Hide comment
@JiantaoFu

JiantaoFu Jun 1, 2015

"<%- toc(page.content, {list_number: true}) %>" adding extra list number, and i can't remove it by {list_number: false}
image

{list_number: true}
image

JiantaoFu commented Jun 1, 2015

"<%- toc(page.content, {list_number: true}) %>" adding extra list number, and i can't remove it by {list_number: false}
image

{list_number: true}
image

@bubkoo

This comment has been minimized.

Show comment
Hide comment
@bubkoo

bubkoo Jun 2, 2015

@JiantaoFu set list-style:none in your css.

bubkoo commented Jun 2, 2015

@JiantaoFu set list-style:none in your css.

@Arnold-Hu

This comment has been minimized.

Show comment
Hide comment
@Arnold-Hu

Arnold-Hu Aug 14, 2015

Could toc function provide the depth option? I think this option could make the page more simple and eligant.

Arnold-Hu commented Aug 14, 2015

Could toc function provide the depth option? I think this option could make the page more simple and eligant.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment