How to allow HTML elments in CKEditor5 in Admin?

Hi all - when I add classes into the CKEditor5 text editor in my admin, the classes get removed when saving. I believe I need to do something like this but I have been struggling on how exactly to implement it. Do I add it to CKEDITOR_5_CONFIGS in settings.py? Or is there another route to take?

I have been trying to add htmlSupport to CKEDITOR_5_CONFIGS in settings.py but I think I’m getting the syntax wrong as it’s either causing an errror or no error but editor not saving html elements like classes. Below is a simplified version of my current configs. I’ve tried several different combinations of syntax but nothing seems to work.

CKEDITOR_5_CONFIGS = {
    'default': {
        'toolbar': ['heading', '|', 'bold', 'italic', 'link',
                    'bulletedList', 'numberedList', 'blockQuote', 'imageUpload', ],
    # Allow HTML elements and attributes
    'htmlSupport': {
        'allow': [
            {
                'name': '/.*/',
                'attributes': True,
                'classes': True,
                'styles': True
            }
            ]
        },
    }

}

Going by this Issue Add General HTML Support · Issue #68 · hvlads/django-ckeditor-5 · GitHub It looks like you should have the “htmlSupport” element within an “extends” element? Not sure if that’s within “default” or not.

I’m not at my laptop right now to try it, but hopefully that helps.

1 Like

Ah, there’s an example here django-ckeditor-5/example/blog/blog/settings.py at 398dad99773bd4050da9accb44532b51483ec384 · hvlads/django-ckeditor-5 · GitHub

1 Like

Thanks so much. That worked!

Great! I often find that searching a project’s Issues on GitHub is a good way to find how people use things.

1 Like