Re: Remove everything below nodes.title/nodes.subtitle from doctree?

David Goodger <[email protected]>
Newsgroups gmane.text.docutils.user
Message-ID <CABiJP=Lq6RuhXCz7sKhoEWUBQfk6fLNZwseBus47R2gfFyNeGw@mail.gmail.com>
On Thu, Oct 12, 2017 at 2:54 PM, Tony N <[email protected]> wrote:
> Since I am already able to read the title/subtitle from the doctree, now I
> want to be able to remove the title and subtitle from a doctree:
>
> What would be the canonical way of doing that?

Docutils doctree elements wrap the sequence interface (pass-through to
Element.children). So use the same operations you would on a list.

> - Removing the nodes.title and nodes.subtitle from the doctree (how can that
> be done? Is there any examples to how that works?)

Assume doctree[0] is the title element (use, e.g. ``index =
Element.first_child_matching_class(nodes.title)``). ``del doctree[0]``
deletes the title.

> - Removing all nodes *after* nodes.title and nodes.subtitle (any examples
> for something like that?)

Assume doctree[1] is the subtitle element. ``del doctree[2:]`` does
what you want.

DG

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.