Re: Question About Section Levels

Kent Borg <[email protected]> Thu, 3 Oct 2019 19:40:01 -0400
Newsgroups gmane.text.docutils.user
Message-ID <[email protected]>
On 10/2/19 4:02 PM, Guenter Milde via Docutils-users wrote:
> implementation sketch:
> * a new option to "include"::
>
>     :relative-section-levels: <offset>
>
> * push the current level and adornment-style--level mapping,
>
> * read the to-be-included file into a list and append an "end marker",
>
> * start a new adornment-style--level mapping
>
> * section_level = parent_level + offset + child_level
>
> * when hitting "end marker": pop section level and adornment-style--level
>    mapping

I don't know the code well, but that seems familiar from what I do know.

Though it seems it would be much harder to do as a custom 
directive--that is, not forking sources, not moving to a new library 
version, etc.

It turns out we have a good (AKA, really unpleasant but we have to do it 
anyway) "workaround": being compatible with some old code means we are 
chopping up content into small enough pieces that we can mostly not have 
our includes do any sections, so we can do them all in a top-level 
document that we can create on-the-fly.

A related question: What are prospects for writing a custom directive 
that does a single section, at an offset-from-current? Or, put another 
way, is there a way from the perspective of a custom directive's 
parse-time code to learn the current section level? If I knew the 
current level I could do a fake include of the right ASCII to indicate 
the section I want to create.

Thanks,

-kb, the Kent who is a big fan of fake includes to do all kinds of things.