Re: Pull dictionary of docinfo fields from a document?
Tony Narlock <[email protected]>
| Newsgroups | gmane.text.docutils.user |
|---|---|
| Message-ID | <CAC8GGzPLt8K2z4ta0tF=pwXQff=Xwh=R_9m4a4=wrF7k=eQ1_Q@mail.gmail.com> |
On July 31, 2017 at 3:03:49 AM, Guenter Milde via Docutils-users ( [email protected]) wrote: On 2017-07-30, Tony Narlock wrote: > My intention is to use DocInfo as a way to scape meta information off RST > files to build an index of them. > There is a DocInfo transformer at docinfo.transforms.frontmatter.DocInfo. > Two things: > 1. I don’t want DocInfo fields to show on HTMLWriter Either hide them with CSS or strip with the setting: --strip-elements-with-class=<class> Remove all elements with classes="<class>" from the document tree. Warning: potentially dangerous; use with caution. (Multiple-use option.) Thanks, I gave both those a shot in my initial run. After a bit more digging, I was able to do this by overriding visit_docinfo in the HTMLWriter: def visit_docinfo(self, node): raise nodes.SkipNode > 2. I want to pull a python dictionary of key->value fields from DocInfo. ... > My understanding is DocInfo handles that fields in biblio_nodes, but also > can handle arbitrary field names. ( > http://docutils.sourceforge.net/docs/ref/doctree.html#docinfo). Is that > true? Yes. Check with, e.g. rst2pseudoxml, this gives a nice representation of the doctree. Then you can, e.g. create a function to convert the docinfo sub-tree into the dict. The transforms will give some hints on how to wald around the doctree and collect information. That helped. In my circumstance, I was able to find some permissively licensed code that did a .traverse(nodes.docinfo) to pluck out a dict of the information. Here is the snippet: https://github.com/adieu/mezzanine-cli/blob/c6feeaf/mezzanine_cli/parser.py#L17 License: https://github.com/adieu/mezzanine-cli/blob/c6feeaf/setup.py#L10 Günter ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot _______________________________________________ Docutils-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/docutils-users Please use "Reply All" to reply to the list. ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot