Skip to main content

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-ins c-if, c-for, c-slot, <c-raw>, and so on) and c-* dynamic attributes.
  • {{ ... }} interpolation, whose body is a Python expression.
  • {# ... #} template comments.
  • The JavaScript in js and the CSS in css.

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pygments_citry-0.1.0.tar.gz (11.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_citry-0.1.0-py3-none-any.whl (9.4 kB view details)

Uploaded Python 3

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

Hashes for pygments_citry-0.1.0.tar.gz
Algorithm Hash digest
SHA256 bd80fa6fa2c0009baa33f20feba862407862c571f095dac1541d356548066c5b
MD5 4e5e2a2580faf3dbadd2aaf1b1c9d4b3
BLAKE2b-256 c67257a22804267f8a7b32f9371f3ebb22a0ab4d9a682825fb15c25ea4f05322

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for pygments_citry-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d80072f9e2189c017c52a10d9504b4dac1692ed1ae93403ea9b3963e55057133
MD5 454e4729ff61375d06b730163512d4ec
BLAKE2b-256 147cbd24b96dc625b1e8ac3b5de3946d5b61a6b4394a7f44598325ab8507f27d

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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