How can i allow "class" in HTMLPurifier? I am trying to purify this:
<div class="txt_r" id="test">Blah</div>
And i get:
<div id="test">Blah</div>
Why class is dissapeared? I am using next config:
$config->set('Attr.EnableID', true);
$config->set('CSS.Trusted', true);
$config->set('HTML.AllowedAttributes', 'style, src, class');
Your problem is probably that HTML.AllowedAttributes
doesn't actually work that way. :) From the docs:
The syntax is "tag.attr" or "*.attr" for the global attributes (style, id, class, dir, lang, xml:lang).
What you probably want is...
$config->set('HTML.AllowedAttributes', 'img.src,*.style,*.class');
You also shouldn't use HTML.AllowedAttributes
by itself, but in tandem with HTML.AllowedElements
:
$config->set('HTML.AllowedElements', 'img,div');
Alternatively, use neither HTML.AllowedAttributes
nor HTML.AllowedElements
and instead use HTML.Allowed
. That would look something like this:
$config->set('HTML.Allowed', 'div, *[style|class], img[src]');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With