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

Discrete Headings: Allow Selective Exclusion from TOC #140

Closed
tajmone opened this issue Apr 26, 2019 · 6 comments · Fixed by #149
Closed

Discrete Headings: Allow Selective Exclusion from TOC #140

tajmone opened this issue Apr 26, 2019 · 6 comments · Fixed by #149
Labels
new-feature Indecates new feature which maintainer planning or under consideration

Comments

@tajmone
Copy link

tajmone commented Apr 26, 2019

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:

<!-- discrete -->
## Some Title

The above heading won't be shown in the generated TOC.

Which would be very similar to how discrete headings are implemented in Asciidoctor:

[discrete] 
== Some Title

The above heading won't be shown in the generated TOC.
@naokazuterada naokazuterada added the feature-request Indicates new feature requests label Apr 28, 2019
@naokazuterada
Copy link
Owner

It looks nice!
I will add it to my TODO list. Thank you.

@naokazuterada naokazuterada added new-feature Indecates new feature which maintainer planning or under consideration and removed feature-request Indicates new feature requests labels Apr 28, 2019
@naokazuterada naokazuterada added this to work in progress in Progress management Apr 28, 2019
@TerminalFi
Copy link
Contributor

[discrete] 
== Some Title

The above heading won't be shown in the generated TOC.

Question, how does this work for cases like the below? Would you still expect Heading 3 to be in the TOC?

# Heading 1


<!-- discrete -->
## Heading 2

### Heading 3

@TerminalFi
Copy link
Contributor

I only ask as I have a local copy that I am working on.

2020-05-18_08-11-03 (1)

@tajmone
Copy link
Author

tajmone commented May 19, 2020

@TheSecEng:

Question, how does this work for cases like the below? Would you still expect Heading 3 to be in the TOC?

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:

1. H1 Regular Example
  1.1. H2 Regular Example
    1.1.1. H3 Regular Example
      1.1.1.1. H4 Regular Example
2. H1 Normal
  2.1. H3 Demoted to H2 in TOC
    2.1.1. H4 Demoted to H3 in TOC

In the second H1 TOC-tree, the H3 entry is rendered as if it was an H2, due to the discrete H2 Discrete entry being omitted from the TOC generation, and all other headings are demoted accordingly.

When converting the above example Asciidoctor issues a warning:

$ asciidoctor test.adoc
asciidoctor: WARNING: test.adoc: line 23: section title out of sequence:
expected level 2, got level 3

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):

A discrete heading is styled in a manner similar to a section title, but is not part of the section hierarchy (i.e., and thus excluded from section nesting requirements), it does not enclose subsequent blocks, and it is not included in the table of contents. The discrete style effectively demotes the section title to a normal heading.

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 [discrete] — i.e. nesting levels are kept consistent, except that discrete headings are excluded from sections numbering calculations and the TOC — whereas in the generated TOC the hierarchy differs.

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.

@TerminalFi
Copy link
Contributor

@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.

@TerminalFi
Copy link
Contributor

@tajmone just wanted to say I should have a PR open today that will support this logic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new-feature Indecates new feature which maintainer planning or under consideration
Projects
Progress management
work in progress
Development

Successfully merging a pull request may close this issue.

3 participants