Skip to main content

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

pygments_ashen-0.1.2.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pygments_ashen-0.1.2-py3-none-any.whl (4.3 kB view details)

Uploaded Python 3

File details

Details for the file pygments_ashen-0.1.2.tar.gz.

File metadata

  • Download URL: pygments_ashen-0.1.2.tar.gz
  • Upload date:
  • Size: 5.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.18

File hashes

Hashes for pygments_ashen-0.1.2.tar.gz
Algorithm Hash digest
SHA256 d51522d3ebea3baa1485437cd47cd0b71ca341a92ccc7e38ec35f54302fc3ae6
MD5 4855c6498aa41c2f742f29f5a5df7460
BLAKE2b-256 68d09cdbef1b3d2add0a855ceb0ec337a9cd68b31736983e4d9f5bfc419e5faa

See more details on using hashes here.

File details

Details for the file pygments_ashen-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for pygments_ashen-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 66c4a3b3469d1c23bc414cf05a0cb6bec2c077971f20669e2d204a311d3c3526
MD5 cd9be3d4a3ae67c76e7b9d6297a7ca19
BLAKE2b-256 81a62970e782449513c67688bcaa74d5554784f29019646738a4b71c3f6ca796

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page