Description
When using long code blocks, say the source code of a full source file which is referenced, it is useful to not only display the line numbers ( which is possible via the :linenos: role ) but also to reference individual lines marked as anchors. This is enabled by pygments in the HTMLFormatter using the lineanchors
option. However this and other options of the same class are not supported by Sphinx.
It is possible to hack this into Sphinx easily adjusting the PygmentsBridge class:
if dest == 'html':
self.fmter = {False: self.html_formatter(style=style)
True: self.html_formatter(style=style,
linenos=True,
lineanchors = 'L')}
It would be preferable to specify this in the code-block directive instead:
.. code-block:: c
:linenos:
:lineanchors:`L`
This together with appropriate semantic markup to reference the location. When missing one can fall back to the .. raw:: directive though, so providing a :lineanchors: attribute is of greater importance.
- Bitbucket: https://bitbucket.org/birkenfeld/sphinx/issue/747
- Originally reported by: schluehk
- Originally created at: 2011-08-05T05:02:16.789