I'm trying to remove every empty element in an input using HTML Purifier, but I want to keep the spans that meet a list of classes. So, for instance:
<div> </div><span class="color-gray"></span><div></div>
Should become:
<span class="color-gray"></span>
The configuration I'm using is:
'AutoFormat.RemoveEmpty.RemoveNbsp' => true,
'AutoFormat.RemoveEmpty' => true,
'CSS.AllowedProperties' => array(),
'Core.RemoveProcessingInstructions' => true,
'HTML.Allowed' => 'a[href|target],h1,h2,p,strong,em,b,i,ul,ol,li,span[class]'
But, as you may imagine, it is not what I expected, as it removes <span>
, too. Do you have any idea on how to solve it?
Mm, you won't be able to do this directly, however, it should be a simple patch to RemoveEmpty; just add an extra check for an attribute at the beginning of handleElement.