CHtmlPurifier, add "style" attribute

I’d like to use CHtmlPurifier to add a “style” attribute to images, like this:


<img style="max-width:100%" src="myimage.jpg" />

Is that possible?

Why would you use CHtmlPurifier for that when its purpose is to remove bad stuff (xss) from your html code and make it standards compliant?

The following adds a rel="nofollow" to <a> tags:


$p = new CHtmlPurifier();

$p->options = array('HTML.Nofollow'=> true);



Therefore, I thought it could be used to add a "style" attribute!

Well, I’m not too familiar with the CHtmlPurifier class but it doesn’t really make much sense to assume that it can add styles to your html elements. If you want to add styles to your images, stick to what actually can do that for you (css/stylesheets).

For a list of configuration options by the way for CHtmlPurifier, I believe you can use this as reference:

http://htmlpurifier.org/live/configdoc/plain.html

You can set HtmlPurifier to allow html tags with options to let end-user use wysiwyg editors.

For image with style set this:

$purifier->options[‘HTML.Allowed’] = ‘img[src|style|alt]’;