Skip to main content

wagtail_editorjs

Check out Awesome Wagtail for more awesome packages and resources from the Wagtail community.

A Wagtail EditorJS widget with page/image chooser support, document support and more!

Add features

Quick start

  1. Add 'wagtail_editorjs' to your INSTALLED_APPS setting like this:

    INSTALLED_APPS = [
    ...,
    'wagtail_editorjs',
    ]
    
  2. Add the HTML to your template:

    <link rel="stylesheet" href="{% static 'wagtail_editorjs/css/frontend.css' %}">
    {% load editorjs %}
    
    {# CSS files for features #}
    {% editorjs_static "css" %}
    
    {% editorjs self.editor_field %}
    
     {# JS files for features #}
     {% editorjs_static "js" %}
    
  3. Add the field to your model:

    ...
    from wagtail_editorjs.fields import EditorJSField
    from wagtail_editorjs.blocks import EditorJSBlock
    
    
    class HomePage(Page):
        content_panels = [
            FieldPanel("editor_field"),
            FieldPanel("content"),
        ]
        editor_field = EditorJSField(
            # All supported features
            features=[
                'attaches',
                'background-color-tune',
                'button',
                'checklist',
                'code',
                'delimiter',
                'document',
                'drag-drop',
                'header',
                'image',
                'images',
                'inline-code',
                'link',
                'link-autocomplete',
                'marker',
                'nested-list',
                'paragraph',
                'quote',
                'raw',
                'table',
                'text-alignment-tune',
                'text-color-tune',
                'text-variant-tune',
                'tooltip',
                'underline',
                'undo-redo',
                'warning'
             ],
            blank=True,
            null=True,
        )
    
        # Or as a block
        content = fields.StreamField([
            ('editorjs', EditorJSBlock(features=[
                # ... same as before
            ])),
        ], blank=True, use_json_field=True)
    

List features

This readme might not fully reflect which features are available.

To find this out - you can:

  1. start the python shell

    py ./manage.py shell
    
  2. Print all the available features:

    from wagtail_editorjs.registry import EDITOR_JS_FEATURES
    print(EDITOR_JS_FEATURES.keys())
    dict_keys([... all registered features ...])
    

Register a Wagtail block as a feature

Warning, this is not available after wagtail 6.2 due to validation errors, TODO: fix this

It is also possible to register a Wagtail block as a feature.

It is important to note that the block must be a StructBlock or a subclass of StructBlock.

It is not allowed to be or include:

  • A StreamBlock (mainly due to styling issues)
  • A ListBlock (mainly due to styling issues)
  • A RichTextBlock (cannot initialize)

Help with these issues is highly appreciated!

Example:

from wagtail import hooks
from wagtail_editorjs.features import (
    WagtailBlockFeature,
    EditorJSFeatureStructBlock,
)
from wagtail_editorjs.registry import (
    EditorJSFeatures,
)
from wagtail_editorjs.hooks import REGISTER_HOOK_NAME

from wagtail import blocks

class HeadingBlock(blocks.StructBlock):
    title = blocks.CharBlock()
    subtitle = blocks.CharBlock()

class TextBlock(EditorJSFeatureStructBlock):
    heading = HeadingBlock()
    body = blocks.TextBlock()

    class Meta:
        template = "myapp/text_block.html"
        allowed_tags = ["h1", "h2", "p"]
        # Html looks like:
        #  <h1>{{ self.heading.title }}</h1>
        #  <h2>{{ self.heading.subtitle }}</h2>
        #  <p>{{ self.body }}</p>

@hooks.register(REGISTER_HOOK_NAME)
def register_editor_js_features(registry: EditorJSFeatures):

    registry.register(
        "wagtail-text-block",
        WagtailBlockFeature(
            "wagtail-text-block",
            block=TextBlock(),
        ),
    )

The block will then be rendered as any structblock, but it will be wrapped in a div with the class wagtail-text-block (the feature name).

Example:

<div class="wagtail-text-block">
    <h1>My title</h1>
    <h2>My subtitle</h2>
    <p>My body</p>
</div>

Settings

EDITORJS_CLEAN_HTML

Default: True Clean the HTML output on rendering. This happens every time the field is rendered. It might be smart to set up some sort of caching mechanism. Optionally; cleaning can be FORCED by passing clean=True or False to the render_editorjs_html function.

EDITORJS_ADD_BLOCK_ID

Default: true Add a block ID to each editorJS block when rendering. This is useful for targeting the block with JavaScript, or possibly creating some link from frontend to admin area.

EDITORJS_BLOCK_ID_ATTR

Default: data-editorjs-block-id The attribute name to use for the block ID. This is only used if ADD_BLOCK_ID is True.

EDITORJS_USE_FULL_URLS

Default: False Use full urls if the request is available in the EditorJS rendering context.

Metadata

Release files for wagtail-editorjs 1.6.6

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-editorjs 1.6.6
File Size Uploaded
wagtail_editorjs-1.6.6.tar.gz 242.4 kB Details

Release files / wagtail_editorjs-1.6.6.tar.gz

Download URL wagtail_editorjs-1.6.6.tar.gz
Size 242.4 kB
Tags Source
SHA-256 checksum
How to use checksums
83ada7ca569bcfa219f39660cef4769a7fd68e2fc03dab2720d990abca66b378
BLAKE2b-256 checksum
How to use checksums
e11847b04a2ea2353ec6ab73687d511bf236fd102a7c924777b72e77dcd6ec30
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.11.6

Release history Release notifications | RSS feed

This release

1.6.6 This release

1 release file

1.6.5

1 release file

1.6.4

1 release file

1.6.3

1 release file

1.6.2

1 release file

1.6.1

1 release file

1.6.0

1 release file

1.5.9

1 release file

1.5.8

1 release file

1.5.7

1 release file

1.5.6

1 release file

1.5.5

1 release file

1.5.4

1 release file

1.5.3

1 release file

1.5.2

1 release file

1.5.1

1 release file

1.5.0

1 release file

1.4.9

1 release file

1.4.8

1 release file

1.4.7

1 release file

1.4.4

1 release file

1.4.3

1 release file

1.4.2

1 release file

1.4.1

1 release file

1.4.0

1 release file

1.3.9

1 release file

1.3.8

1 release file

1.3.7

1 release file

1.3.6

1 release file

1.3.5

1 release file

1.3.4

1 release file

1.3.3

1 release file

1.3.2

1 release file

1.3.1

1 release file

1.3.0

1 release file

1.2.9

1 release file

1.2.8

1 release file

1.2.7

1 release file

1.2.6

1 release file

1.2.5

1 release file

1.2.4

1 release file

1.2.2

1 release file

1.2.1

1 release file

1.2.0

1 release file

1.1.9

1 release file

1.1.8

1 release file

1.1.7

1 release file

1.1.6

1 release file

1.1.5

1 release file

1.1.4

1 release file

1.1.3

1 release file

1.1.2

1 release file

1.1.1

1 release file

1.1.0

1 release file

1.0.9

1 release file

1.0.8

1 release file

1.0.7

1 release file

1.0.6

1 release file

1.0.5

1 release file

1.0.4

1 release file

1.0.3

1 release file

1.0.2

1 release file

1.0.1

1 release file

1.0.0

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