Pete Posted November 12, 2014 Posted November 12, 2014 Hi guys I've been trying to allow rel=nofollow in links when editing the source of a page in CKEditor but it strips them out when the page is saved. CKEditor version is 4.2.0 (older version of the module but not too old I don't think). I can get it to work if I turn off the HTMLPurifier option in the field's Input tab but would rather not do that. I thought perhaps something like a[rel](*) in the Extra Allowed Content field might work but it doesn't. Any suggestions? I'm sure it will be something simple.
gebeer Posted November 13, 2014 Posted November 13, 2014 I can confirm same behaviour for CKEditor 4.4.3 I also tried it with the native CKEditor link plugin. But I couldn't get it to work, either, other than switching off HTMLPurifier :-( 1
interrobang Posted November 13, 2014 Posted November 13, 2014 The module docs say:To specify custom settings to HTML Purifier, perform set() calls before calling purify(). So I guess something like this should work, if placed on top of your templates before you output your fields. $purifier = wire('modules')->get('MarkupHTMLPurifier'); $purifier->set('Attr.AllowedRel', array('nofollow')); I did not try this myself. If this doesn't work when placed in your template files I would try placing it in the admin.php in your templates folder. 2
kongondo Posted November 13, 2014 Posted November 13, 2014 I think in template files would be too late? The stripping already happens in the page edit.
interrobang Posted November 13, 2014 Posted November 13, 2014 Looking at the sources you seem to be right. The value gets saved already purified. But it should work when you place the snippet in admin.php in your templates folder An alternative way would be to edit InputfieldCKEditor.module in site/modules. Around line 262 the purifier is used and configured. 1
Pete Posted November 13, 2014 Author Posted November 13, 2014 Thanks for the input guys - it didn't seem to work in the admin.php template and, yes, the actual frontend template would be too late. For now, I edited the MarkupHTMLPurifier module and changed the purify() function around line 108 to this: public function purify($html) { $this->set('Attr.AllowedRel', array('nofollow')); return $this->getPurifier()->purify($html); } That works a treat I think it would be a relatively trivial task to make it so we can have config options with this module, so I might have a look into that over the weekend unless someone beats me to it! 2
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