Opened 4 years ago

Last modified 3 years ago

#4586 enhancement new

Code-listings generated by lore2sphinx should include line-numbers

Reported by: Screwtape Owned by:
Priority: normal Milestone: Lore to Sphinx
Component: core Keywords: documentation
Cc: khorn, thijs Branch:
Author: Launchpad Bug:

Description

exarkun, in ticket #4566 comment 5:

One thing I noticed while reviewing this, though, is that code listings no longer have line numbers. Could you file a ticket for that?

It looks like Lore puts line-numbers on <pre class="python"> blocks, but not on python-interpreter or shell blocks.

From what I can see in the Sphinx docs, this can be enabled on a per-document basis with a fragment of code like:

.. highlight:: python
   :linenothreshold: 1

...but it would be even better if that could be set as a project-wide setting; I'm not sure if that's possible.

Change History (4)

comment:1 Changed 4 years ago by khorn

This can also be set for individual code blocks like so:

.. code-block:: python
   :linenos:

   Code goes here...

As far as a project-wide setting for :linenothreshold:, I don't think this is possible (at least not yet).

Also, I believe the "highlight" directive only works on blocks that begin with "::", rather than ".. code-block", but I'm not positive about that.

comment:2 Changed 4 years ago by <automation>

  • Owner glyph deleted

comment:3 Changed 4 years ago by thijs

  • Cc thijs added
  • Milestone set to Lore to Sphinx

comment:4 Changed 3 years ago by khorn

After some investigation, it seems that the "linenothreshold" option of the "highlight" directive only works on automatically-highlighted blocks, which as far as I can tell means blocks beginning with "::" and blocks included with the "literalinclude" directive.

Blocks created with "code-block" directives do not recognize the "linenothreshold" option. Line numbers can be enabled on them, but need to be done so individually.

It shouldn't be too difficult to get lore2sphinx to generate the proper options for the "code-block" directives to show line numbers if we decide we want it to.

Note: See TracTickets for help on using tickets.