Skip to content

Allow for more pygments.formatters.html.HTMLFormatters options #747

@shimizukawa

Description

@shimizukawa

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.


Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy