Re: Using DocUtils to parse RST with unknown directives
David Goodger <[email protected]>
| Newsgroups | gmane.text.docutils.user |
|---|---|
| Message-ID | <CABiJP=JpNPjMN3y5B=9Xehrgze5g=6KW=3TaFi5qd2YXXw+hDA@mail.gmail.com> |
On Mon, Jul 21, 2014 at 1:07 PM, Austin Bart <[email protected]> wrote: > I have some RST files that use a number of custom directives. I need to get > a tree-based representation (e.g., like I'd get from publish_doctree) of > these files before I pass them into Sphinx (via Paver) and have them parsed > properly. I don't want any sophisticated processing of the directives - I > just want to know where in the document any given directive occurs, along > with its options and content. > > If I try and just pass the files into publish_doctree, it gets upset because > it hasn't been told about all the custom directives that are possible. Is my > only option to implement my own parser? Or is there some way to tell > docutils to not Except on unknown directives? The following conversation > makes me think that it might not be possible: > > http://article.gmane.org/gmane.text.docutils.user/4176/match=publish_doctree You can adjust the halt_level so that "error" level does not halt the processing. You'd set halt_level=4 (one level above error = 3). Then the resulting doctree would contain error messages with details about each directive. Another option would be some monkey-patching. Replace docutils.parsers.rst.directives._directive_registry (in the __init__.py file) with a collections.defaultdict(your_function), duplicating the original _directive_registry's data. The implementation of your_function would return a (module name, class name) tuple; you would have to implement these as well (possibly also monkey-patched). I recommend the first option, much easier. If it doesn't do what you want, the second option may do it for you. -- David Goodger <http://python.net/~goodger> > Please note that I'm not subscribed to this listserv, so please CC me on > responses! Thanks for your time and help! > > -- > Austin Cory Bart > Computer Science PhD student at Virginia Tech > http://www.acbart.com > > ------------------------------------------------------------------------------ > Want fast and easy access to all the code in your enterprise? Index and > search up to 200,000 lines of code with a free copy of Black Duck > Code Sight - the same software that powers the world's largest code > search on Ohloh, the Black Duck Open Hub! Try it now. > http://p.sf.net/sfu/bds > _______________________________________________ > Docutils-users mailing list > [email protected] > https://lists.sourceforge.net/lists/listinfo/docutils-users > > Please use "Reply All" to reply to the list. > ------------------------------------------------------------------------------ Want fast and easy access to all the code in your enterprise? Index and search up to 200,000 lines of code with a free copy of Black Duck Code Sight - the same software that powers the world's largest code search on Ohloh, the Black Duck Open Hub! Try it now. http://p.sf.net/sfu/bds