Judging from our comment conversation, you appear to be more interested in tidying your HTML rather than sanitising it. As such, HTML Purifier is probably not the right tool for you. You could look into PHP's Tidy module (a wrapper for HTML Tidy), or check out alternatives.
If you do want to teach HTML Purifier to accept script tags, HTML.Trusted
is the right setting. That said, HTML Purifier does not currently support HTML5 and therefore does not understand HTML5-only attributes like async
. To teach HTML Purifier that attribute, you need to follow the instructions on the Enduser "Customize" documentation.
In your case the first step to take is to add this to your code:
$config = HTMLPurifier_Config::createDefault();
$config->set('HTML.DefinitionID', 'enduser-customize.html tutorial');
$config->set('HTML.DefinitionRev', 1);
$config->set('Cache.DefinitionImpl', null); // remove this later!
$def = $config->getHTMLDefinition(true);
$def->addAttribute('script', 'async', 'Bool#async');
This teaches HTML Purifier that async
is an expected boolean value for the tag. If you want to allow the charset
attribute, try:
$def->addAttribute('script', 'charset', 'Enum#utf-8');
...or whatever other charsets you want to support. If you want to support any value:
$def->addAttribute('script', 'charset', 'CDATA');