This is the legacy rich text editor for the Wagtail CMS. Based on Hallo.js.
As of Wagtail 2.0, the hallo.js editor is deprecated.
Status See supported versions for Wagtail compatibility, however, this package will no longer receive bug fixes or be actively maintained. Pull requests will be accepted and if maintainers wish to support this outside of the core Wagtail team, please raise an issue to discuss this.
pip install wagtail-hallo
'wagtail_hallo'
to your settings.py INSTALLED_APPS
To use wagtail-hallo on Wagtail, add the following to your settings:
WAGTAILADMIN_RICH_TEXT_EDITORS = {
'hallo': {
'WIDGET': 'wagtail_hallo.hallo.HalloRichTextArea'
}
}
RichTextField
# models.py
from wagtail.admin.panels import FieldPanel
from wagtail.fields import RichTextField
from wagtail.models import Page
class MyHalloPage(Page):
body = RichTextField(editor='hallo')
content_panels = Page.content_panels + [
FieldPanel('body', classname='full'),
]
{% extends "base.html" %}
{% load wagtailcore_tags wagtailimages_tags %}
{% block content %}
{% include "base/include/header.html" %}
<div class="container">
<div class="row">
<div class="col-md-7">{{ page.body|richtext }}</div>
</div>
</div>
{% endblock content %}
StreamField
via RichTextBlock
# models.py
from wagtail.models import Page
from wagtail.blocks import CharBlock, RichTextBlock
from wagtail.admin.panels import FieldPanel
from wagtail.fields import StreamField
class MyOtherHalloPage(Page):
body = StreamField([
('heading', CharBlock(form_classname="full title")),
('paragraph', RichTextBlock(editor='hallo')),
], blank=True)
content_panels = Page.content_panels + [
FieldPanel('body'),
]
{% extends "base.html" %}
{% load wagtailcore_tags wagtailimages_tags %}
{% block content %}
{% include "base/include/header.html" %}
<div class="container">
<div class="row">
<div class="col-md-7">{{ page.body }}</div>
</div>
</div>
{% endblock content %}
The legacy hallo.js editor’s functionality can be extended through plugins. For information on developing custom hallo.js
plugins, see the project's page: https://github.com/bergie/hallo.
Once the plugin has been created, it should be registered through the feature registry's register_editor_plugin(editor, feature_name, plugin)
method. For a hallo.js
plugin, the editor
parameter should always be 'hallo'
.
A plugin halloblockquote
, implemented in myapp/js/hallo-blockquote.js
, that adds support for the <blockquote>
tag, would be registered under the feature name block-quote
as follows:
from wagtail import hooks
from wagtail_hallo.plugins import HalloPlugin
@hooks.register('register_rich_text_features')
def register_embed_feature(features):
features.register_editor_plugin(
'hallo', 'block-quote',
HalloPlugin(
name='halloblockquote',
js=['myapp/js/hallo-blockquote.js'],
)
)
The constructor for HalloPlugin
accepts the following keyword arguments:
name
- the plugin name as defined in the JavaScript code. hallo.js
plugin names are prefixed with the "IKS."
namespace, but the name passed here should be without the prefix.options
- a dictionary (or other JSON-serialisable object) of options to be passed to the JavaScript plugin code on initialisationjs
- a list of JavaScript files to be imported for this plugin, defined in the same way as a Django form media definitioncss
- a dictionary of CSS files to be imported for this plugin, defined in the same way as a Django form media definitionorder
- an index number (default 100) specifying the order in which plugins should be listed, which in turn determines the order buttons will appear in the toolbarWhen writing the front-end code for the plugin, Wagtail’s Hallo implementation offers two extension points:
[data-hallo-editor]
attribute selector to target the editor, eg. var editor = document.querySelector('[data-hallo-editor]');
..halloeditor
class selector.After extending the editor to support a new HTML element, you'll need to add it to the whitelist of permitted elements - Wagtail's standard behaviour is to strip out unrecognised elements, to prevent editors from inserting styles and scripts (either deliberately, or inadvertently through copy-and-paste) that the developer didn't account for.
Elements can be added to the whitelist through the feature registry's register_converter_rule(converter, feature_name, ruleset)
method. When the hallo.js
editor is in use, the converter
parameter should always be 'editorhtml'
.
The following code will add the <blockquote>
element to the whitelist whenever the block-quote
feature is active:
from wagtail.admin.rich_text.converters.editor_html import WhitelistRule
from wagtail.whitelist import allow_without_attributes
@hooks.register('register_rich_text_features')
def register_blockquote_feature(features):
features.register_converter_rule('editorhtml', 'block-quote', [
WhitelistRule('blockquote', allow_without_attributes),
])
WhitelistRule
is passed the element name, and a callable which will perform some kind of manipulation of the element whenever it is encountered. This callable receives the element as a BeautifulSoup Tag object.
The wagtail.whitelist
module provides a few helper functions to assist in defining these handlers: allow_without_attributes
, a handler which preserves the element but strips out all of its attributes, and attribute_rule
which accepts a dict specifying how to handle each attribute, and returns a handler function. This dict will map attribute names to either True (indicating that the attribute should be kept), False (indicating that it should be dropped), or a callable (which takes the initial attribute value and returns either a final value for the attribute, or None to drop the attribute).
All contributions are welcome as the Wagtail core team will no longer be actively maintaining this project.
git clone git@github.com:wagtail/wagtail-hallo.git
.pip3 install -e ../path/to/wagtail-hallo/
-> this installs the package locally as editable'wagtail_hallo'
is added to your settings.py INSTALLED_APPS
test/testapp/models.py
for a reference modeltest/testapp/templates/hallo_test_page.html
for a reference templatepython manage.py makemigrations
and python manage.py migrate
python testmanage.py test
django-admin makemigrations --settings=wagtail_hallo.test.settings
flake8 wagtail_hallo
black wagtail_hallo
Currently the frontend tooling is based on Node & NPM and is only used to format and check code. This repository intentionally does not use any build tools and as such JavaScript and CSS must be written without that requirement.
nvm use
- Ensures you are on the right node versionnpm install --no-save
- Install NPM packagesnpm run fix
- Parses through JS/CSS files to fix anything it cannpm run lint
- Runs lintingnpm run format
- Runs Prettier formatting on most files (non-Python)npm test
- Runs tests (Jest)npm test -- --watch
- Runs tests in watch mode (Jest)npm run preflight
- Runs all the linting/formatting/jest checks and must be done before committing codeVERSION
in wagtail_hallo/__init__.py
tox.ini
, setup.py
, README.md
, package.json
and workflows/ci.yml
with new supported Python, Django, or Wagtail versionsnpm install
to ensure the package-lock.json
is updated"Development Status :: # - Alpha"
based on status (# being a number) in setup.py
setup.py
with new release versionCHANGELOG.md
with the release datepip install twine
python3 setup.py clean --all sdist bdist_wheel
twine upload dist/*
<-- pushes to PyPIstable/1.0.x
)v1.0.0
)Many thanks to all of our supporters, contributors, and users of Wagtail who built upon the amazing Hallo.js editor. We are thankful to the Wagtail core team and developers at Torchbox who sponsored the majority of the initial development. Thank you to LB, who transferred the Hallo.js integration from Wagtail to the wagtail-hallo package. And a very special thanks to the original creator of the Hallo.js editor.