Pygments lexer for Citry components: highlights the HTML, JS, and CSS embedded in a component's template/js/css strings
Project description
pygments-citry
A Pygments lexer for Citry
components. It highlights a component the way an editor would: the Python class,
plus the HTML, JavaScript, and CSS embedded in its template, js, and css
string attributes, each in its own language.
Without it, a Citry component in a ```python block renders the template,
JS script, and CSS stylesheet as flat string literals. With it, a ```citry
block colours the <c-*> tags, the {{ ... }} interpolation, the embedded
stylesheet, and the embedded script.
Install
pip install pygments-citry
The package registers a citry lexer as a Pygments plugin, so any tool that
resolves lexers by name picks it up once it is installed.
Use it
On the command line:
pygmentize -l citry my_component.py
In Python:
from pygments import highlight
from pygments.formatters import HtmlFormatter
from pygments.lexers import get_lexer_by_name
lexer = get_lexer_by_name("citry")
html = highlight(source, lexer, HtmlFormatter())
In a Markdown site (mkdocs with pymdownx.highlight / pymdownx.superfences,
or any python-markdown setup that resolves Pygments lexers by name), tag the
fence with citry:
```citry
from citry import Component
class Welcome(Component):
template = """
<div class="card">
<h1>{{ title }}</h1>
<p c-if="count">You have {{ count }} new messages.</p>
</div>
"""
```
No superfences custom_fences entry is needed: once the package is installed,
citry resolves like any other Pygments lexer.
What it highlights
A citry block is highlighted as Python, and the following Citry constructs
inside the template / js / css attributes are highlighted in their own
language:
- The HTML in
template, including the<c-*>component and control-flow tags (the built-insc-if,c-for,c-slot,<c-raw>, and so on) andc-*dynamic attributes. {{ ... }}interpolation, whose body is a Python expression.{# ... #}template comments.- The JavaScript in
jsand the CSS incss.
The <c-raw>...</c-raw> element is treated as verbatim text, matching the
engine: {{ }} and tags inside it are not interpreted.
Template-only blocks: citry-html
For a fenced block that shows only a template, with no surrounding Python (just
<c-*> tags, {{ ... }}, and {# ... #}), tag it citry-html:
```citry-html
<c-for each="item in items">
<li c-if="item.visible">{{ item.label }}</li>
</c-for>
```
citry expects full component code (Python with embedded strings), so a bare
template belongs in a citry-html block instead.
License
MIT. Part of the Citry project.
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
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_citry-0.1.0.tar.gz.
File metadata
- Download URL: pygments_citry-0.1.0.tar.gz
- Upload date:
- Size: 11.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bd80fa6fa2c0009baa33f20feba862407862c571f095dac1541d356548066c5b
|
|
| MD5 |
4e5e2a2580faf3dbadd2aaf1b1c9d4b3
|
|
| BLAKE2b-256 |
c67257a22804267f8a7b32f9371f3ebb22a0ab4d9a682825fb15c25ea4f05322
|
Provenance
The following attestation bundles were made for pygments_citry-0.1.0.tar.gz:
Publisher:
py--pygments-citry--publish.yml on citry-dev/citry
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pygments_citry-0.1.0.tar.gz -
Subject digest:
bd80fa6fa2c0009baa33f20feba862407862c571f095dac1541d356548066c5b - Sigstore transparency entry: 2257378552
- Sigstore integration time:
-
Permalink:
citry-dev/citry@e43ddf200da1ad77141504547930ce020a44d7ee -
Branch / Tag:
refs/tags/pygments-citry@0.1.0 - Owner: https://github.com/citry-dev
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
py--pygments-citry--publish.yml@e43ddf200da1ad77141504547930ce020a44d7ee -
Trigger Event:
push
-
Statement type:
File details
Details for the file pygments_citry-0.1.0-py3-none-any.whl.
File metadata
- Download URL: pygments_citry-0.1.0-py3-none-any.whl
- Upload date:
- Size: 9.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d80072f9e2189c017c52a10d9504b4dac1692ed1ae93403ea9b3963e55057133
|
|
| MD5 |
454e4729ff61375d06b730163512d4ec
|
|
| BLAKE2b-256 |
147cbd24b96dc625b1e8ac3b5de3946d5b61a6b4394a7f44598325ab8507f27d
|
Provenance
The following attestation bundles were made for pygments_citry-0.1.0-py3-none-any.whl:
Publisher:
py--pygments-citry--publish.yml on citry-dev/citry
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pygments_citry-0.1.0-py3-none-any.whl -
Subject digest:
d80072f9e2189c017c52a10d9504b4dac1692ed1ae93403ea9b3963e55057133 - Sigstore transparency entry: 2257378564
- Sigstore integration time:
-
Permalink:
citry-dev/citry@e43ddf200da1ad77141504547930ce020a44d7ee -
Branch / Tag:
refs/tags/pygments-citry@0.1.0 - Owner: https://github.com/citry-dev
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
py--pygments-citry--publish.yml@e43ddf200da1ad77141504547930ce020a44d7ee -
Trigger Event:
push
-
Statement type: