Sphinx, literalinclude, linenos: how to display actual line numbers from a source code file in a document code fragment?

I am using Sphinx to document portions 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 is derived from lines 47-51 of the actual source code file, not 1-5.

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

+5
source share
2 answers

This was not possible when a question was asked in 2011, but now there is a function lineno-start(added in Sphinx 1.3). See this improvement request: https://github.com/sphinx-doc/sphinx/issues/668 .

+5
source
+2

All Articles