How to traverse and modify nodes in included source?

14 views
Skip to first unread message

Konstantin Molchanov

unread,
Jun 14, 2017, 2:17:27 PM6/14/17
to sphinx-dev
Hi! I’m trying to develop an extension for including rst sources from git repos. Including the source itself is trivial, but I need to adjust the image paths in order to keep them visible in the final doc.

To do that, I need to parse the included source, traverse through its nodes, find all `image` nodes, and modify their content.

Any suggestions on how to do that?

Here’s the question on Stackoverflow, so if you know the answer, you could get some karma: https://stackoverflow.com/questions/44546652/how-do-i-traverse-and-modify-nodes-in-included-source

Guenter Milde

unread,
Jun 14, 2017, 3:14:03 PM6/14/17
to sphin...@googlegroups.com
On 2017-06-14, Konstantin Molchanov wrote:

> [-- Type: text/plain, Encoding: quoted-printable --]

> Hi! I’m trying to develop an extension for including rst sources from git
> repos. Including the source itself is trivial, but I need to adjust the
> image paths in order to keep them visible in the final doc.

> To do that, I need to parse the included source, traverse through its
> nodes, find all `image` nodes, and modify their content.

> Any suggestions on how to do that?

The docutils.nodes (sub)module has utility functions for such tasks.
Have a look at the Docutils "transforms" for usage examples.

Günter

Reply all
Reply to author
Forward
0 new messages