Skip to main content

A block render syntax highlighter for Wagtail CMS.

Project description

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/.

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

wagtail-pygments-0.1.1.tar.gz (3.0 kB view details)

Uploaded Source

Built Distribution

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

wagtail_pygments-0.1.1-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

File details

Details for the file wagtail-pygments-0.1.1.tar.gz.

File metadata

  • Download URL: wagtail-pygments-0.1.1.tar.gz
  • Upload date:
  • Size: 3.0 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for wagtail-pygments-0.1.1.tar.gz
Algorithm Hash digest
SHA256 cf59a611f2b4167c601e2066ec82bac3ab95d66b909f25be3786a1047e2b49b4
MD5 869c5ae3ee7b8a8ed08e7b5cf83bf4be
BLAKE2b-256 7f91c3fe6abee055de3b41f3cfdd85dd92a1c327ab81892cdd109e8d76ddfafa

See more details on using hashes here.

File details

Details for the file wagtail_pygments-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: wagtail_pygments-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 4.5 kB
  • Tags: Python 3
  • Uploaded using 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

File hashes

Hashes for wagtail_pygments-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c9c2a892b247a47cfa8404655e1dfc3d43e6a65d04be2e8383a9fbd9894fdb6f
MD5 93935963b05a8046740df975e8de8809
BLAKE2b-256 3e6ec0faed843149493b5366c023ff1af4153a38a806db6386ce9d92d72934b3

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