Robin S Posted August 23, 2018 Share Posted August 23, 2018 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? 5 Link to comment Share on other sites More sharing options...
szabesz Posted August 24, 2018 Share Posted August 24, 2018 "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. 1 Link to comment Share on other sites More sharing options...
Macrura Posted August 31, 2018 Share Posted August 31, 2018 same here, looks like i need data- attributes available on paragraph elements... 2 Link to comment Share on other sites More sharing options...
Robin S Posted September 2, 2018 Author Share Posted September 2, 2018 I opened a request on GitHub: https://github.com/processwire/processwire-requests/issues/226 @Macrura, I noticed this post of yours from a while ago: Were you only able to achieve the data attributes by disabling HTML Purifier on the CKEditor field? 1 Link to comment Share on other sites More sharing options...
Macrura Posted September 2, 2018 Share Posted September 2, 2018 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 More sharing options...
TheMick Posted May 17, 2021 Share Posted May 17, 2021 For those who are searching: The mentioned request was completed (https://github.com/processwire/processwire-requests/issues/226) and there is a hook now. 2 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now