Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When using deeply nested sections, the numbering of the headings started to get messy. This is the problem at the core of issues #83, #111 and #123, which I believe would be fixed by this PR.
This PR revamps the ToC generation, both on the sidebar and the printed page, to always navigate the sections recursively and provide a predictable, simple, "classic" (as per this comment) numbering scheme.
It also works on and expands the scope of PR #115, as it has been frozen for quite some time, and its scope was slightly more limited.
Besides, total line count has been greatly reduced, and some aspects of the code have been simplified.
Note, however, that here we have opted to leave the inner headings outside the ToC of the printed document
This was done to keep the print page ToC consistent with the sidebar ToC, but this is different from the original approach. It could be discussed whether including the inner headings in the print-page ToC is desired (and whether the sidebar should be consistent with this).
Little example (left is old, right is new):

Another example (based on PR #115).
Old sidebar (omits elements and has obscure numbering):

New sidebar:
