Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way in Sphinx/Pygments to emphasize one or more lines of code in literal includes?

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.

like image 781
Casey Duncan Avatar asked Mar 18 '10 20:03

Casey Duncan


1 Answers

Sphinx now has an emphasize-lines directive for literal includes:

http://sphinx-doc.org/markup/code.html#includes

like image 173
Jason Polites Avatar answered Oct 31 '22 16:10

Jason Polites