Skip to main content

Highlighting ranges in pygments

Project description

Highlight ranges of code in pygments output.

This provides a filter that uses spor anchors to determine which ranges of code to highlight in the pygmentized output. You specify the ranges by creating anchors with metadata where the key “highlight” is true, e.g.:

{"highlight": true}

Quick start

First, install highlight-ranges. See the “Installation” section for details.

Create a directory somewhere and create a file named with the following contents:

def func(x):
    y = x * 4
    return y

Now initialize a spor repository and add an anchor that will highlight the second line in the file:

spor init
spor add 17 9 5

Finally, use the highlight-ranges filter to generate the pygmentized HTML of the code:

pygmentize -l python3 -f html -O full -F > example.html

If you open example.html in a browser, you should see the second line in the code emphasized.


You can install from PyPI with pip::

pip install highlight-ranges

Or you can install from source:

pip install .


The filter marks highlighted ranges of code with the Generic.Emph type. From a CSS point of view, this means you can style the highlights via the ge class.

Filter options

The file being pygmentized.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for highlight-ranges, version 1.0.0
Filename, size File type Python version Upload date Hashes
Filename, size highlight_ranges-1.0.0.tar.gz (3.5 kB) File type Source Python version None Upload date Hashes View
Filename, size highlight_ranges-1.0.0-py3-none-any.whl (5.6 kB) File type Wheel Python version py3 Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page