Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You could patch sphinx's LiteralInclude directive in sphinx/directives/code.py</p> <ul> <li>There you would need to do something such that when you include code you can specify a start/end line to emphasize in this snippet.</li> <li>The second step would require creating some ways to highlight things differently. The simplest approach is that the part with no emphasis is not highlighted and the part with emphasis is highlighted. That would avoid doing more complex hacking of the styles and highlighting.</li> </ul> <p>This gives for instance a new lines-emphasis option in the literalinclude directive that you can use this way:</p> <pre><code>.. literalinclude:: ../sphinx/directives/code.py :pyobject: Highlight :lines-emphasis: 6,13 </code></pre> <p>where line-emphasis is a start line, end line relative to the included code, first line is 1.</p> <p>Using sphinx 0.6.5 at pypi.python.org/pypi/Sphinx/0.6.5 as a base a quicky patched code.py is there: <a href="http://paste.pocoo.org/show/194456/" rel="nofollow noreferrer">http://paste.pocoo.org/show/194456/</a></p> <p>Note that the following would be equivalent:</p> <p>Using the standard sphinx (pretty much what S.Lott suggested):</p> <pre><code>.. literalinclude:: ../sphinx/directives/code.py :language: none :lines: 0-36 .. literalinclude:: ../sphinx/directives/code.py :lines: 36-46 .. literalinclude:: ../sphinx/directives/code.py :language: none :lines: 37- </code></pre> <p>... and using the patched sphinx:</p> <pre><code>.. literalinclude:: ../sphinx/directives/code.py :lines-emphasis: 37,47 </code></pre> <p>Therefore it may no be exactly what you are looking for. The patch creates a new node for each of the highlighted or not highlighted sections of the code. Each of these will be rendered by Sphinx as a separate &lt; div > and &lt; pre > section. To go beyond this you may want to create a stylesheet that would better excerpt the lines with emphasis. Further hacks might need to go deep in the guts of Sphinx and Pygments to have a seamless emphasized style generated directly there: not trivial.</p> <p>/HTH</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload