-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Bernhard Leiner schrieb: > Hi! > > In one of my applications [1] I'm using the docutils.core.publish_doctree > method to parse rst files. This method directly returns the doctree which I > use to display some information about the file (currently the structure of the > file and parsing errors/warnings). > > Now I would like to add support for Sphinx. My basic requirement is pretty > simple: I would like to get the doctree of a single rst file which contains > Sphinx specific markup (no support for extensions for the moment). > > So far I can think about two possibilities for the implementation: > > 1. Via an extension that adds a custom Builder (the doctree is passed > as an argument to the `write_doc` method) > 2. A more low level approach that creates a > sphinx.environment.BuildEnvironment instance (as far as I understood it, > Sphinx directives and roles are registered at this point and are known by > docutils afterwards) and uses one of the docutils publish methods. > > The first approach seems a bit clunky but it uses the official API... > > Any hints how to proceed? Is there a better way to do this?
It depends a bit on what you want to do with the doctree. Basically, after read by the environment, the doctrees still contain some nodes specific to Sphinx (e.g. pending_xrefs), which are then removed before passed to the writer. Just registering the Sphinx roles and directives won't work since they expect a BuildEnvironment instance to be available where they can store and get information, but you can instantiate a BuildEnvironment and read your document via its update() method. cheers, Georg -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.11 (GNU/Linux) iEYEARECAAYFAkr3WMsACgkQN9GcIYhpnLCzSACcCSGBa/5LwxxCF3AtKMJnwUy9 LrgAn1mn3pX0K6ipb2CaoG9ZAe4xBpcW =ZM71 -----END PGP SIGNATURE----- --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sphinx-dev" group. To post to this group, send email to sphinx-dev@googlegroups.com To unsubscribe from this group, send email to sphinx-dev+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sphinx-dev?hl=en -~----------~----~----~----~------~----~------~--~---