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 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.2.tar.gz
(3.5 kB
view hashes)
Built Distribution
Close
Hashes for pygments_promql-0.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b187d43093d72ec46f326ad1deca6eb7482444379b12f7740a064fa90ee255ce |
|
MD5 | 1bfa969657e3ace3f1ccbc9680d5f516 |
|
BLAKE2b-256 | e1c6bb605c50ed42b1bbff5c85642bee5ba8c1fa290462a1cad2dff284883d97 |