Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sphinx, literalinclude, linenos: How to display the actual line numbers from the source code file on the doc's code snippet?

I am using Sphinx to document parts of Javascript code on a web page.

I use

.. literalinclude:: ../examples/mapviz-step1-simple.html
   :language: javascript
   :lines: 47-51
   :linenos:

I get

enter image description here

The code snippet comes from lines 47-51 of the actual source code file, not 1-5.

How can I display the actual line numbers along with this snippet of code?

like image 339
b_dev Avatar asked Jul 29 '11 02:07

b_dev


2 Answers

This was not possible when the question was asked in 2011, but since Sphinx 1.3 there is lineno-start option. See this enhancement request: https://github.com/sphinx-doc/sphinx/issues/668.

Current documentation:

  • literalinclude
  • code-block
like image 114
mzjn Avatar answered Nov 07 '22 05:11

mzjn


Sphinx 1.3 will have lineno-start feature available just for this purpose.

like image 38
anatoly techtonik Avatar answered Nov 07 '22 05:11

anatoly techtonik