Modifying htmlpurifier allowed tags for this markup

sameold picture sameold · Jun 3, 2011 · Viewed 7.1k times · Source

My html purifier settings now allow only these tags

$configuration->set('HTML.Allowed', 'p,ul,ol,li');

I want to allow indentation of lists and my editor uses this html

<ul style="margin-left: 40px;">

How should I change my HTMLPurifier Allowed tags? I thought to add style, but I think it would be better to specify exactly which style is allowed, which in this case would be margin-left. What is the right way to change the HTML.Allowed for this case?

Answer

Edward Z. Yang picture Edward Z. Yang · Jun 3, 2011

Allow the style attributes, and then modify the allowed CSS attributes using %CSS.AllowedProperties.

$configuration->set('HTML.Allowed', 'p,ul[style],ol,li');
$configuration->set('CSS.AllowedProperties', 'margin-left');

P.S. I'm surprised how many people don't understand how HTML Purifier works.