pygments-lexer-spl
A Pygments lexer plugin for the Splunk Search Processing Language (SPL). Pygments is the default syntax highlighter for Sphinx (and therefore Read the Docs). This package adds Splunk SPL support to Pygments.
Installation
Install the package directly:
pip install pygments-lexer-spl
Or add it to your project's dependencies:
# pyproject.toml
[project]
dependencies = [
"pygments-lexer-spl",
]
Usage
Once installed, the lexer is automatically available to Pygments via the plugin entry point. You can use it with any Pygments-compatible tool.
Command line (pygmentize)
pygmentize -l spl example.spl
pygmentize -l splunk example.spl
Python API
from pygments import highlight
from pygments.formatters import TerminalFormatter
from pygments_lexer_spl import SPLLexer
code = open('example.spl').read()
print(highlight(code, SPLLexer(), TerminalFormatter()))
Terminal preview
python preview.py
DEBUG=1 python preview.py # Print each token and its type
Visual preview server
pip install 'pygments-lexer-spl[server]'
python server.py
# Then open http://localhost:8080
MkDocs
Install pygments-lexer-spl alongside MkDocs. The lexer is picked up
automatically via the Pygments plugin entry point, so no extra configuration is
required. Use the spl language identifier in fenced code blocks:
```spl
index=main sourcetype=access_combined
| stats count BY host
```
Sphinx
Install pygments-lexer-spl in the same environment as Sphinx. The lexer
registers itself automatically, so it is available in code-block directives
without any additional configuration:
.. code-block:: spl
index=main sourcetype=access_combined
| stats count BY host
Flask
Use Pygments directly to render highlighted HTML and serve it from a Flask route:
from flask import Flask
from pygments import highlight
from pygments.formatters import HtmlFormatter
from pygments_lexer_spl import SPLLexer
app = Flask(__name__)
formatter = HtmlFormatter()
@app.route("/highlight")
def highlight_code():
code = open("example.spl").read()
highlighted = highlight(code, SPLLexer(), formatter)
css = f"<style>{formatter.get_style_defs('.highlight')}</style>"
return css + highlighted
Django
Add Pygments to your Django project and call it from a view or template tag:
# views.py
from django.utils.safestring import mark_safe
from pygments import highlight
from pygments.formatters import HtmlFormatter
from pygments_lexer_spl import SPLLexer
formatter = HtmlFormatter()
def highlight_code(request):
from django.shortcuts import render
code = open("example.spl").read()
highlighted = highlight(code, SPLLexer(), formatter)
css = formatter.get_style_defs(".highlight")
return render(request, "highlight.html", {
"css": mark_safe(css),
"code": mark_safe(highlighted),
})
{# highlight.html #}
<style>{{ css }}</style>
{{ code }}
Colors
The lexer tells Pygments how to identify tokens. Pygments wraps each token in a
span tag with a class related to that token type. If you want to change how
the tokens are highlighted, change themes or add custom CSS.
Supported aliases
| Alias | Description |
|---|---|
spl |
Primary alias |
splunk |
Alternative alias |
splunk-spl |
Fully qualified alias |
Development
Install dependencies:
pip install -e ".[dev,server]"
Run the test suite:
pytest
Start the visual preview server (available at http://localhost:8080):
python server.py
Run the terminal preview script:
python preview.py
Enable debug mode to print each token and its value:
DEBUG=1 python preview.py
License
MIT
Metadata
Release files for pygments-lexer-spl 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pygments_lexer_spl-0.1.0.tar.gz | 7.4 kB | Without provenance | Details for pygments_lexer_spl-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pygments_lexer_spl-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for pygments_lexer_spl-0.1.0-py3-none-any.whl |
Total release size: 14.8 kB
Release files / pygments_lexer_spl-0.1.0.tar.gz
| Download URL | pygments_lexer_spl-0.1.0.tar.gz |
|---|---|
| Size | 7.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0cda7942069c8dcc57c791c02e081f828088762dcbb270e3160ceac4a2c214a6
|
|
BLAKE2b-256 checksum How to use checksums |
e6a7ec4a8612ed38f3394b7bb60ec75d4b55d7f16b77af6cfc5bd4167d4c9986
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.6.17
|
Release files / pygments_lexer_spl-0.1.0-py3-none-any.whl
| Download URL | pygments_lexer_spl-0.1.0-py3-none-any.whl |
|---|---|
| Size | 7.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ca93e1def59ca5eb9c1e599d94528156e971234750956a5f5ca0cf4fc5f12d2f
|
|
BLAKE2b-256 checksum How to use checksums |
a0b29fb5892f0215b7ef5b414032de9e8606b17576a057d9633c22198f4b4917
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.6.17
|
Security for pygments-lexer-spl 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.