Sphinx,literalinclude,linenos:如何在doc的代码片段中显示源代码文件中的实际行号?

时间:2011-07-29 02:12:55

标签: python-sphinx

我正在使用Sphinx在网页上记录部分Javascript代码。

我用

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

我得到了

enter image description here

代码段来自实际源代码文件的第47-51行,而不是1-5。

如何显示实际行号以及此代码段?

2 个答案:

答案 0 :(得分:5)

在2011年提出问题时,这是不可能的,但现在有一个lineno-start功能(在Sphinx 1.3中添加)。请参阅此增强请求:https://github.com/sphinx-doc/sphinx/issues/668

答案 1 :(得分:2)

Sphinx 1.3 will have lineno-start功能仅用于此目的。