Search code examples
phpxsshtmlpurifier

HtmlPurifier - allow name attribute


how can I allow 'name' in HtmlPurifier ? I try to use like this :

config = HTMLPurifier_Config::createDefault();
$config->set('HTML.AllowedAttributes', 'img._src, img.name, img.src,img.alt');
return HtmlPurifier::process($html, $config);

but it not work ? How can I do? thx


Solution

  • See this config option: http://htmlpurifier.org/live/configdoc/plain.html#HTML.Attr.Name.UseCDATA

    The W3C specification DTD defines the name attribute to be CDATA, not ID, due to limitations of DTD. In certain documents, this relaxed behavior is desired, whether it is to specify duplicate names, or to specify names that would be illegal IDs (for example, names that begin with a digit.) Set this configuration directive to true to use the relaxed parsing rules.