Skip to main content

A block render syntax highlighter for Wagtail CMS.

Project description

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 }}
    {% 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 Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

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

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: wagtail_pygments-0.1-py3-none-any.whl
  • Upload date:
  • Size: 4.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.8.3

File hashes

Hashes for wagtail_pygments-0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f097f20b22dc899758d45c8ceb557ba37a115dcb1f6580d67276feb9c4059517
MD5 23d38bf8bd562104d84539a4321ea9fa
BLAKE2b-256 4dec3f7d35eaffc1313a824ea60cea61b16959155e80acd2cdc1413f0eae4ab2

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