A PromQL lexer for Pygments
Project description
pygments-promql
A PromQL lexer for Pygments.
This Python package provides a Pygments lexer for the Prometheus Query Language. It allows Pygments and other tools (Sphinx, Chroma, etc) to highlight PromQL queries.
Installation
Using pip
To get the latest version from pypi.org:
pip install pygments-promql
Usage
Command-line
The following examples are using queries from tests/example.promql
Showing colorized output in a terminal:
pygmentize tests/example.promql
Or to generate a PNG file:
pygmentize -f png -O "line_numbers=False,style=monokai" -o example.png tests/example.promql
Python code
The following example:
from pygments import highlight
from pygments.formatters import HtmlFormatter
from pygments_promql import PromQLLexer
query = 'http_requests_total{handler="/api/comments"}'
print(highlight(query, PromQLLexer(), HtmlFormatter()))
will generate this HTML output:
<div class="highlight">
<pre>
<span></span>
<span class="nv">http_requests_total</span>
<span class="p">{</span>
<span class="nl">handler</span>
<span class="o">=</span>
<span class="s">"/api/comments"</span>
<span class="p">}</span>
<span class="w"></span>
</pre>
</div>
Use HtmlFormatter(noclasses=True)
to include CSS inline styles on every <span>
tag.
Testing
If you want to test, play or contribute to this repo:
git clone https://github.com/pabluk/pygments-promql.git
cd pygments-promql/
pip install -r requirements.txt
pip install -e .
pytest -v
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
pygments-promql-0.0.3.tar.gz
(3.4 kB
view hashes)
Built Distribution
Close
Hashes for pygments_promql-0.0.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 70cea75bc6de44f54b80a74ddb99697b3d8416b787134fe1c90c228d9e05a085 |
|
MD5 | aca10278ae4bfaa938abc7fe5e594da3 |
|
BLAKE2b-256 | 2af67375dc1592f3cb7a78b462c0198b04094c59ba80df0f6726131f8d9403bf |