Package: wagtail-hallo
Wagtail Hallo - Rich Text EditorThis is the legacy rich text editor for the Wagtail CMS. Based onHallo.js.As ofWagtail 2.0, the hallo.js editor is deprecated.StatusThis package should be compatible with Wagtail 2.17 and earlier versions. However, it 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.Major risks of using this packagePlease be aware of theknown hallo.js issuesshould you want to keep using it.Hallo.js has inappropriate handling of HTML and editor input – it is not reliable, has browser-specific inconsistent behavior, is not a good user experience and is not accessible.This package is a source of security concerns (XSS injections, not CSP compatible) and allows injection of undesirable content or formatting (e.g. images in headings, or headings in lists).There is no guarantee that this package will be compatible with Wagtail beyond the supported versions listed above.Release NotesSee theChangelog.Supported VersionsPython 3.7, 3.8, 3.9Django 3.2. 4.0Wagtail 2.15, 2.16, 3.0Installing the Hallo Editorpip install wagtail-halloAdd'wagtail_hallo'to your settings.pyINSTALLED_APPSTo use wagtail-hallo on Wagtail 2.x, add the following to your settings:WAGTAILADMIN_RICH_TEXT_EDITORS={'hallo':{'WIDGET':'wagtail_hallo.hallo.HalloRichTextArea'}}Using the Hallo Editor inRichTextField# models.pyfromwagtail.admin.edit_handlersimportFieldPanelfromwagtail.core.fieldsimportRichTextFieldfromwagtail.core.modelsimportPageclassMyHalloPage(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" %}<divclass="container"><divclass="row"><divclass="col-md-7">{{ page.body|richtext }}</div></div></div>{% endblock content %}Using the Hallo Editor inStreamFieldviaRichTextBlock# models.pyfromwagtail.core.modelsimportPagefromwagtail.core.blocksimportCharBlock,RichTextBlockfromwagtail.admin.edit_handlersimportStreamFieldPanelfromwagtail.core.fieldsimportStreamFieldclassMyOtherHalloPage(Page):body=StreamField([('heading',CharBlock(form_classname="full title")),('paragraph',RichTextBlock(editor='hallo')),],blank=True)content_panels=Page.content_panels+[StreamFieldPanel('body'),]{% extends "base.html" %}
{% load wagtailcore_tags wagtailimages_tags %}

{% block content %}
    {% include "base/include/header.html" %}<divclass="container"><divclass="row"><divclass="col-md-7">{{ page.body }}</div></div></div>{% endblock content %}Extending the Hallo EditorThe legacy hallo.js editor’s functionality can be extended through plugins. For information on developing customhallo.jsplugins, see the project's page:https://github.com/bergie/hallo.Once the plugin has been created, it should be registered through the feature registry'sregister_editor_plugin(editor, feature_name, plugin)method. For ahallo.jsplugin, theeditorparameter should always be'hallo'.A pluginhalloblockquote, implemented inmyapp/js/hallo-blockquote.js, that adds support for the<blockquote>tag, would be registered under the feature nameblock-quoteas follows:fromwagtail.coreimporthooksfromwagtail_hallo.pluginsimportHalloPlugin@hooks.register('register_rich_text_features')defregister_embed_feature(features):features.register_editor_plugin('hallo','block-quote',HalloPlugin(name='halloblockquote',js=['myapp/js/hallo-blockquote.js'],))The constructor forHalloPluginaccepts the following keyword arguments:name- the plugin name as defined in the JavaScript code.hallo.jsplugin 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 aDjango form mediadefinitioncss- a dictionary of CSS files to be imported for this plugin, defined in the same way as aDjango form mediadefinitionorder- 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:In JavaScript, use the[data-hallo-editor]attribute selector to target the editor, eg.var editor = document.querySelector('[data-hallo-editor]');.In CSS, use the.halloeditorclass selector.Whitelisting rich text elementsAfter 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'sregister_converter_rule(converter, feature_name, ruleset)method. When thehallo.jseditor is in use, theconverterparameter should always be'editorhtml'.The following code will add the<blockquote>element to the whitelist whenever theblock-quotefeature is active:fromwagtail.admin.rich_text.converters.editor_htmlimportWhitelistRulefromwagtail.core.whitelistimportallow_without_attributes@hooks.register('register_rich_text_features')defregister_blockquote_feature(features):features.register_converter_rule('editorhtml','block-quote',[WhitelistRule('blockquote',allow_without_attributes),])WhitelistRuleis 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 aBeautifulSoupTag object.Thewagtail.core.whitelistmodule 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, andattribute_rulewhich 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).ContributingAll contributions are welcome as the Wagtail core team will no longer be actively maintaining this project.Development instructionsTo make changes to this project, first clone this repositorygit clone git@github.com:wagtail/wagtail-hallo.git.Python (Django / Wagtail)pip3 install -e ../path/to/wagtail-hallo/-> this installs the package locally aseditableEnsure'wagtail_hallo'is added to your settings.pyINSTALLED_APPSYou will need to have a test application (e.g.Bakery Demo) and have a Page model to work with, along with a template.seetest/testapp/models.pyfor a reference modelseetest/testapp/templates/hallo_test_page.htmlfor a reference templateAfter creating the model, remember to runpython manage.py makemigrationsandpython manage.py migrateRun testspython testmanage.py testRun migrations for test modelsdjango-admin makemigrations --settings=wagtail_hallo.test.settingsRun lintingflake8 wagtail_halloRun formattingblack wagtail_halloJavaScript & CSS (Frontend)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 run preflight- Runs all the linting/formatting/jest checks and must be done before committing codeRelease checklistUpdateVERSIONinwagtail_hallo/__init__.pyUpdatetox.ini,setup.py,README.md,package.jsonandworkflows/ci.ymlwith new supported Python, Django, or Wagtail versionsRunnpm installto ensure thepackage-lock.jsonis updatedUpdate classifiers (e.g."Development Status :: # - Alpha"based on status (# being a number) insetup.pyUpdatesetup.pywith new release versionUpdateCHANGELOG.mdwith the release datePush to PyPIpip install twinepython3 setup.py clean --all sdist bdist_wheeltwine upload dist/*<-- pushes to PyPICreate a stable release branch (e.g.stable/1.0.x)Add a Github release (e.g.v1.0.0)ThanksMany 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.