Ideally such changes should be at the level of the asciidoc source code, but we do not have any idea of whether this is important enough for the asciidoc developers. So at the moment we plan to do this as ad hoc changed to the css/js in the asciidoc output. Basically we translate the existing flat list of headings into tree structures and then enable hiding / showing of headings at lower heading levels. The way we do this is by inserting css/js code at the very end of the document, thus not messing with the asciidoc js output. This means that each time we produce a new asciidoc document we have to append our own changes to the end of the document.
The important question is: do you have any suggestions about how to organise these changes in a way that is resistant to unrelated changes to the asciidoc source code?