In some sphinx docs I am writing, I am including code samples from an ancillary file like so:
.. literalinclude:: mymodule.py
:pyobject: MyClass
:linenos:
This particular doc is a tutorial, where the classes are build up step by step. What I would like to do is include the entire class or a single method, and emphasize only the lines of interest to that section. That way the context is preserved but the interesting parts are obvious at a glance. Right now I have resorted to just referring to line numbers in the text, which is ok, but far from ideal.
Looking at the docs and code for sphinx and pygments I don't find an obvious way to do this. I'm not opposed to patching them or doing something tricky in conf.py
, but I wondered if anyone had solved this.
Sphinx now has an emphasize-lines
directive for literal includes:
http://sphinx-doc.org/markup/code.html#includes
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With