Skip to main content
https://badge.fury.io/py/wagtail-pygments.svg

A block render syntax highlighter for Wagtail CMS.

Install

pip install -i wagtail-pygments

Example Usage

  1. Use with StreamBlock:

    from wagtail_pygments.blocks import CodeBlock
    
    class ContentStreamBlock(StreamBlock):
        heading = TextBlock()
        paragraph = TextBlock()
        code = CodeBlock(label='Code')
  2. Use with StreamField:

    from wagtail_pygments.blocks import CodeBlock
    
    class PostPage(Page):
        body = StreamField([
            ('paragraph', RichTextBlock()),
            ('image', ImageChooserBlock()),
            ('embed', EmbedBlock()),
            ('code', CodeBlock())
        ])
  3. Example for django template:

    {% load static %}
    <link rel="stylesheet" href="{% static 'css/monokai.css' %}">
    
    {% for block in page.body %}
    {% if block.block_type == "code" %}
        {{ block.value.code }}
        {% if block.value.caption %}
            <!-- Caption -->
            <figcaption>
              {{ block.value.caption }}
            </figcaption>
        {% endif %}
    {% else %}
        {{ block.value }}
    {% endif %}
    {% endfor %}

Languages

Configuring WAGTAIL_CODE_BLOCK_LANGUAGES in your Django settings:

WAGTAIL_CODE_BLOCK_LANGUAGES = (
    ('cpp', 'C++'),
    ('java', 'Java'),
    ('python3', 'Python 3'),
    ('bash', 'Bash/Shell'),
    ('javascript', 'Javascript'),
    ('css', "CSS"),
    ('html', "HTML"),
    ('julia', "Julia"),
    ('nginx', "Nginx configuration file"),
    ('numpy', "NumPy"),
    ('django', "Django"),
    ('jinja', "Jinja"),
    ('docker', "Docker"),
    ('jinja', "Jinja"),
    ('yaml', "YAML"),
    ('json', "JSON"),
    ('plpgsql', "PL/pgSQL"),
    ('psql', "PostgreSQL console (psql)"),
)

Can check full list in https://pygments.org/docs/lexers/.

Metadata

Release files for wagtail-pygments 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for wagtail-pygments 0.1.1
File Size Uploaded
wagtail-pygments-0.1.1.tar.gz 3.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for wagtail-pygments 0.1.1
File Interpreter ABI Platform
wagtail_pygments-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 7.5 kB

Release files / wagtail-pygments-0.1.1.tar.gz

Download URL wagtail-pygments-0.1.1.tar.gz
Size 3.0 kB
Tags Source
SHA-256 checksum
How to use checksums
cf59a611f2b4167c601e2066ec82bac3ab95d66b909f25be3786a1047e2b49b4
BLAKE2b-256 checksum
How to use checksums
7f91c3fe6abee055de3b41f3cfdd85dd92a1c327ab81892cdd109e8d76ddfafa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.3

Release files / wagtail_pygments-0.1.1-py3-none-any.whl

Download URL wagtail_pygments-0.1.1-py3-none-any.whl
Size 4.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c9c2a892b247a47cfa8404655e1dfc3d43e6a65d04be2e8383a9fbd9894fdb6f
BLAKE2b-256 checksum
How to use checksums
3e6ec0faed843149493b5366c023ff1af4153a38a806db6386ce9d92d72934b3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.3

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page