-
Notifications
You must be signed in to change notification settings - Fork 48
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
Discrete Headings: Allow Selective Exclusion from TOC #140
Comments
It looks nice! |
Question, how does this work for cases like the below? Would you still expect Heading 3 to be in the TOC?
|
@TheSecEng:
Yes, but it would be rendered as a level-2 entry in the TOC, to preserve sequence consistency (and any nested entries will be demoted accordingly). Taking Asciidoctor as the reference implementation for this feature, if you render this sample document: = Discrete Headers tests
:sectnums:
:sectnumlevels: 5
:toc: left
:toclevels: 5
== H1 Regular Example
=== H2 Regular Example
==== H3 Regular Example
===== H4 Regular Example
// Same as above, but H3 is out of sequence due to H2 being discrete...
== H1 Normal
[discrete]
=== H2 Discrete
==== H3 Demoted to H2 in TOC
===== H4 Demoted to H3 in TOC
it produces the following TOC:
In the second H1 TOC-tree, the H3 entry is rendered as if it was an H2, due to the discrete When converting the above example Asciidoctor issues a warning:
but it's not an error by any means, and it's shown just in case the author didn't want this to happen. Discrete headings don't have to abide to section nesting requirements, as mentioned in Asciidoctor Manual, §16.8. Discrete Headings (emphasis added):
Although the documentation doesn't provide the implementation details on how the final TOC is adjusted, from the above example we can infer that discrete headings are skipped in TOC generation, and that nesting levels are adapted in order to preserve a consistent sequence in the final TOC (regardless of how the actual headings are rendered in the document). The above example shows that in the final HTML document the actual heading levels are unaffected by the That is how Asciidoctor implements the feature. Of course, this package is not bound to follow Asciidoctor, but since the feature is inspired from Asciidoctor I personally think it would make sense to follow its implementation. |
@tajmone thanks for the detailed explanation. I will continue to work on my branch and see if I can get this fully working as expected. |
@tajmone just wanted to say I should have a PR open today that will support this logic. |
Purpose
In very long documents it might useful to selectively exclude some sections from the generated TOC, like Asciidoctor's discrete headings.
How important it is
It would greatly improve control over generated TOCs, allowing to use the full depth of TOC levels without creating needlessly huge TOCs.
For example, if a README doc also contains the full text of a long license with many subsections (e.g. the Artistic License), all its subheadings could be excluded from the generated TOC, showing only "Artistic License" or "License".
Ideal implementation
Maybe exploiting html comments like this:
Which would be very similar to how discrete headings are implemented in Asciidoctor:
The text was updated successfully, but these errors were encountered: