Pygments style for Ashen
Project description
Pygments Ashen
This repository contains the Pygments style plugin for the
Ashen theme. Available as the pygments-ashen
package on PyPI for use in your
Python projects, or with the Pygments CLI tool. The actual name of the style
within pygments is ashen.
How To Use
The following shows how to use the style with uv, which is currently the
cleanest way to manage Python projects and libraries. You may, of course,
install the package into a virtual environment with pip, if you wish:
pip install pygments-ashen
Pygments CLI
Third-party Pygments styles are Python packages that must be available in the
environment pygments is running in. For example, you can use uv to create a
one-off environment for a single command:
uv run --with 'pygments-ashen,pygments' \
pygmentize -O full,style=ashen \
-l python -f html foobar.py > foobar.html
The above command invokes pygmentize with the pygments-ashen and pygments
dependencies available, and renders the file foobar.py in HTML format with the
Ashen theme applied.
In Your Projects
If your project uses Pygments for code highlighting, you can easily add support
for Ashen. The pygments-ashen package must be installed in the project
environment:
uv add pygments-ashen
Then, you can use ashen as the style in Pygments formatters. Here's an
example from Zona. This code renders a Markdown code block in HTML with Ashen
highlighting, using the marko library:
# method part of subclass of marko.html_renderer.HTMLRenderer
@override
def render_fenced_code(self, element: FencedCode):
# pygments expects a single string, not a list of lines
code = "".join(child.children for child in element.children)
# fallback to "text" if no language specified
lang = element.lang or "text"
# load the correct pygments lexer
try:
lexer = get_lexer_by_name(lang, stripall=False)
except Exception:
lexer = TextLexer(stripall=False)
# use the "ashen" style, requires pygments-ashen package
formatter = HtmlFormatter(style="ashen", nowrap=True, noclasses=True)
# highlight the code
highlighted = highlight(code, lexer, formatter)
# return rendered code block
return (
f'<pre class="code-block language-{lang}">'
f"<code>{highlighted}</code></pre>"
)
Project details
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pygments_ashen-0.1.1.tar.gz.
File metadata
- Download URL: pygments_ashen-0.1.1.tar.gz
- Upload date:
- Size: 5.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a39f8277fcfddc7f7c10fc5cfe8695b7fc4ede9776b2d25b2ad8a6b33af1bbd5
|
|
| MD5 |
bc9cfa15bca7e046d4259fa3fc8e5b61
|
|
| BLAKE2b-256 |
f2115246b1ec9a14bbd32970773894ad3ea4a42569e1a72e90f8aff859b43f63
|
File details
Details for the file pygments_ashen-0.1.1-py3-none-any.whl.
File metadata
- Download URL: pygments_ashen-0.1.1-py3-none-any.whl
- Upload date:
- Size: 4.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
28fd415a38b0168a2134b96a09f34169197229a299ba4d781a8319fc5d7f5e67
|
|
| MD5 |
6e9bd9229a2056c24ceffe343179457e
|
|
| BLAKE2b-256 |
4927f8a48a1a49c422309d6bcd1d2722a19dd90006777d1e972e4b1e128d081c
|