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

Unexpected result when including h1 headers #36

Closed
oleersoy opened this issue Jul 16, 2013 · 7 comments
Closed

Unexpected result when including h1 headers #36

oleersoy opened this issue Jul 16, 2013 · 7 comments

Comments

@oleersoy
Copy link

Tried this:

var toc = $("#toc").tocify({ selectors: "h1,h2,h3,h4,h5" }).data("toc-tocify");

Now only the first h1 header and its child shows up in the toc.

@oleersoy
Copy link
Author

It seems like testing toc generation would be simpler if the the selectors were limited to [startHeaderLevel, endHeaderLevel]. So something like:

var toc = $("#toc").tocify({ startSelector: "h1", endSelector: "h5"}).data("toc-tocify");

@oleersoy
Copy link
Author

Reading up on the html 5 documentation tags.

https://developer.mozilla.org/en-US/docs/Web/HTML/Sections_and_Outlines_of_an_HTML5_document

Something to note is that subsections can "restart" the header hierarchy.
Might be useful to support a feature allowing the specification of section depth support. For example only outline top level sections or allow sections to a depth level of 3.

@ghost ghost assigned gfranko Jul 26, 2013
@gfranko
Copy link
Owner

gfranko commented Jul 27, 2013

Tried this:

var toc = $("#toc").tocify({ selectors: "h1,h2,h3,h4,h5" }).data("toc-tocify");

Now only the first h1 header and its child shows up in the toc.

@oleersoy So this can be confusing, but the reason you are only seeing the h1 header and it's child show up in the toc is because the other header elements are NOT siblings of the h1 header. Tocify loops through each first selector on the page and then expects all of the subheaders to either be siblings of children of the first header.

It seems like testing toc generation would be simpler if the the selectors were limited to [startHeaderLevel, endHeaderLevel]. So something like:

var toc = $("#toc").tocify({ startSelector: "h1", endSelector: "h5"}).data("toc-tocify");

Specifying a starting and ending selector would limit some flexibility. For example, what if you only wanted to use h2 and h4 tags? You couldn't do that with a start and end selector, since that would also include an h3 element.

Reading up on the html 5 documentation tags.

https://developer.mozilla.org/en-US/docs/Web/HTML/Sections_and_Outlines_of_an_HTML5_document

Something to note is that subsections can "restart" the header hierarchy.
Might be useful to support a feature allowing the specification of section depth support. For example only outline top level sections or allow sections to a depth level of 3.

Very interesting. I like being able to set up section tags to reset the hierarchy. Pull requests are always welcome =)

@gfranko gfranko closed this as completed Jul 27, 2013
@oleersoy
Copy link
Author

Hi,

Sorry for the late reply. I somehow missed the github email about this issue. I'm still getting up to speed on github, git, jquery, and jqueryui and reading your code has been very helpful. I hope to be able to submit pull requests soon.

I think it would be helpful if there was a document like:
https://developer.mozilla.org/en-US/docs/Web/HTML/Sections_and_Outlines_of_an_HTML5_document

That showed markup and correspondingly how the outline would be generated with respect to the markup. I'll write it up if you think it would be useful.

@gfranko
Copy link
Owner

gfranko commented Aug 13, 2013

@oleersoy No worries! That would be great if you could help contribute to this project. I also agree with you that there should be documentation around how the TOC is generated based on the HTML you are using.

@oleersoy
Copy link
Author

Cool - I'll start writing it up ASAP.

@oleersoy
Copy link
Author

oleersoy commented Oct 9, 2013

Doing some research before starting beginning to write, and it turns out there's already an official spec for the algorithm that determines the document outline. The mozilla article sort of hints at it, but this makes it a lot more clear:

http://coding.smashingmagazine.com/2011/08/16/html5-and-the-document-outlining-algorithm/
http://developers.whatwg.org/sections.html#headings-and-sections

Do you think it's good enough to just reference this material?

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

No branches or pull requests

2 participants