question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Rich editor configuration per field

See original GitHub issue

There is some things that could be added to rich text:

  • add support for different configurations
  • needs a way to unregister some plugins globally (there is only hooks for enabling a hallojs plugin)
  • make default whitelister configurable, for example disable “a” tag globally.

Example of rich text editor configuration for a field

# Simple TextArea, where we nee just a few options on editor
class SimpleDbWhitelister(WagtailDbWhitelister):
    element_rules = {
        '[document]': allow_without_attributes,
        'a': attribute_rule({'href': check_url}),
        'p': allow_without_attributes,
        'b': allow_without_attributes,
        'i': allow_without_attributes,
        'u': allow_without_attributes,
    }


class SimpleRichTexArea(WagtailRichTextArea):
    hallo_plugins = {
        'halloheadings': {
            'formatBlocks': []
        },
        'halloformat': {
            'formattings': {
                "bold": True,
                "italic": True,
            },
        },
        'hallolists': {
            "lists": {
                "ordered": False,
                "unordered": False
            }
        },
        'hallowagtaillink': {},
        'hallorequireparagraphs': {},
        'hallocleanhtml': {
            'format': False,
            'removeTags': ['span', 'div', 'table', 'strong'],
            'allowedTags': ['a', 'p', 'i', 'b', 'u'],
            'removeAttrs': ['class', 'style', 'id'],
            'allowedAttributes': [
                ["a", ['href', 'target', 'data-id', 'data-linktype']]
            ]
        }
    }

    def render_js_init(self, id_, name, value):
        return "makeRichTextEditable({0}, {1});".format(
            json.dumps(id_),
            json.dumps(self.hallo_plugins)
        )

    def value_from_datadict(self, data, files, name):
        original_value = super(SimpleRichTexArea, self).value_from_datadict(data, files, name)
        if original_value is None:
            return None
        return SimpleDbWhitelister.clean(original_value)

Some changes on page-editor.js

function makeRichTextEditable(id, plugins) {
   var instanceHalloPlugins = plugins || halloPlugins;
....
}

Globally disable a hallo plugin on editor

function unRegisterHalloPlugin(name) {
    if (!$.inArray(name, disabledHalloPlugins)) {
        disabledHalloPlugins.push(name);
    }
    if ($.inArray(name, halloPlugins)) {
        delete halloPlugins[name];
    }
}

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:12 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
gasmancommented, Jul 26, 2017

Now implemented in #3736.

(To correct myself above: #2697 only addresses this in a very basic way - you’d need to set up a configuration in WAGTAILADMIN_RICH_TEXT_EDITORS for each combination of features - and only for editors that recognise configuration options passed there, which hallo.js didn’t until I implemented that in #3736)

1reaction
gasmancommented, Sep 19, 2016

I believe #2697 (now in master) should address this. Haven’t had chance to try it out myself, and it still needs docs, but if anyone’s up for trying it out and reporting back, that would be much appreciated!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Configuring the Rich Text Editor - HubSpot Developers
The Rich Text Editor inside of custom modules now provides the ability for developers to remove components from the configuration toolbar.
Read more >
Rich text editor configuration - Xperience 13 Documentation
Assign editor configurations to rich text fields​​ For fields that use the Rich text editor form component, you can set custom configurations via ......
Read more >
Configure the Rich Text Editor | Adobe Experience Manager
The Rich Text Editor (RTE) provides authors with a wide range of functionality for editing their text content. Icons, selection boxes, toolbar, ...
Read more >
Rich Text Editor Document: Configuration Reference
Name Default Description toolbarMobile mobile The toolbar set on mobile devices. timeoutAddToUndo 900 When uses types fast, wait 900ms to add undo item. insertRowTag Default row...
Read more >
Configure Rich Text Editor settings - ThoughtFarmer Helpdesk
You can reorder the tools as desired. Add "/" to start a new row in the toolbar. Remember to surround the entire config...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found