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 example.py 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 example.py 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 highlight-ranges:file=example.py example.py > example.html
If you open example.html in a browser, you should see the second line in the code emphasized.
Installation
You can install from PyPI with pip::
pip install highlight-ranges
Or you can install from source:
pip install .
Styling
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
- file
The file being pygmentized.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file highlight_ranges-1.0.0.tar.gz
.
File metadata
- Download URL: highlight_ranges-1.0.0.tar.gz
- Upload date:
- Size: 3.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5e677fd1d50fba186dee4391b3dd5de5f2c59a49469773d8fcf6cf28cfd44b21 |
|
MD5 | 726feb42730642d1b4bafc25065d5d8d |
|
BLAKE2b-256 | 34ee1882b1a027b559cb05b1f3b84499a6c3b24329c4ce3ecf466cfcdb66f1f8 |
File details
Details for the file highlight_ranges-1.0.0-py3-none-any.whl
.
File metadata
- Download URL: highlight_ranges-1.0.0-py3-none-any.whl
- Upload date:
- Size: 5.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0ac2a28ab9c3f001a218332bd75f77657138730b73e112794eec5c4366d224de |
|
MD5 | 0a55582b4fd366cbffd9c3c992a9e6ad |
|
BLAKE2b-256 | 8d096facec819590e50823b7d43549c3451d7ac3620a127a308b85a652f00963 |