Jump to content

Is HTML Purifier configurable in PW?

Robin S

Recommended Posts

When "Use HTML Purifier" is enabled for a CKEditor field any data-* attributes are stripped out. This happens regardless of the CKEditor ACF settings, and is pretty annoying considering how frequently data attributes are used/needed these days.

I'd like to keep HTML Purifier activated but I want to change the configuration to allow specific data attributes.

I know how to do this via addAttribute()  - as mentioned here - and I can get this working if I directly edit MarkupHTMLPurifier::init() and clear the HTML Purifier cached files from /site/assets/cache/.

public function init() {
    $this->settings->set('Cache.SerializerPath', $this->getCachePath());
    $this->settings->set('Attr.AllowedRel', array('nofollow'));
    $this->settings->set('HTML.DefinitionID', 'html5-definitions');
    $this->settings->set('HTML.DefinitionRev', 1);
    if($def = $this->settings->maybeGetRawHTMLDefinition()) {
        $def->addElement('figure', 'Block', 'Optional: (figcaption, Flow) | (Flow, figcaption) | Flow', 'Common');
        $def->addElement('figcaption', 'Inline', 'Flow', 'Common');

        // Added line below to allow data-ext attribute on 'a' elements
        $def->addAttribute('a', 'data-ext', 'Text');

But how can I change the configuration like this without modifying a core file? I want to set the configuration from a custom module. I don't see any hookable methods in MarkupHTMLPurifier but surely it must be configurable somehow. Does anyone know a way to do this?

  • Like 5
Link to comment
Share on other sites

"Is HTML Purifier configurable in PW?"
I searched the forum for this a few days ago, and the answer to this question was: NO.

We do need core support for this, preferably in the admin. And it is not just data- attributes, but a class attribute not set by CKE was stripped too in my case. 

  • Like 1
Link to comment
Share on other sites

I haven't tested the current use case, in terms of disabling HTML Purifier, i was hoping i could do it without having to resort to that, though i'd guess it should work (?).

In this scenario, I am worried about users pasting in junk, so I think i want to keep the purifier, but allow very specific custom markup, as  i'm using @BitPoet's CK editor inline actions to allow users to reference other pages, and/or special 'media' pages that can hold things like images, videos and audio.

In the case of videos, i was going to have the insert be a simple poster image for the video and then on output i would look for paragraph with a data attribute, and then replace the image in that paragraph with a clickable poster image to the video, probably using something like Magnific..

Link to comment
Share on other sites

  • 2 years later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...