gfranko / jquery.tocify.js

A jQuery Table of Contents plugin that can be themed with Twitter Bootstrap or jQueryUI.
http://gregfranko.com/jquery.tocify.js/
MIT License
927 stars 217 forks source link

Trouble using selectors option #55

Closed ezietsman closed 10 years ago

ezietsman commented 10 years ago

Hi,

I have some documents I want to use tocify on. I'm having trouble to get tocify to use the elements I want. The document looks as follows:

div.section
    h1.title This is a chapter
    div.section
        h2.title This is a section
        div.activity
            h1.title This is an activity title
        div.section
            h3.title This is a subsection
    div.section
        h2.title This is another section

In which case the toc should look like:

1. This is a chapter
    1.1 This is a section
        1.1.1 This is a subsection
    1.2 This is another section

and the div.activity > h1 should be ignored.

I've tried to use the selectors option in various ways e.g.

selectors : "div.section>h1.title, div.section>h2.title, div.section>h3.title"

and

selectors : "h1#toc-id-0,h2#toc-id-1,h3#toc-id-2,h3#toc-id-3,h2#toc-id-4,h3#toc-id-5,h2#toc-id-6"

but it won't give the correct ToC. Can tocify do what I want? If not can you give me some pointers as to what I can do to add this functionality and send a pull request?

gfranko commented 10 years ago

The reason this isn't working is because of the content algorithm that Tocify uses (referenced in #46 ). If you change the h1.title This is an activity title from being a header, it should work as you expect.

Here is a good read to understand it more: http://developers.whatwg.org/sections.html#headings-and-sections

And a good quote from that article:

The first element of heading content in an element of sectioning content represents the heading for that section. Subsequent headings of equal or higher rank start new (implied) sections, headings of lower rank start implied subsections that are part of the previous one. In both cases, the element represents the heading of the implied section.