Question

I am needing the code that will allow my users to input centered text and not have htmlpurifier strip it out.

Thanks!

Was it helpful?

Solution

Grabbing half the answer from your(?) HTML Purifier thread:

$config = HTMLPurifier_Config::createDefault();
$config->set('CSS.AllowedProperties', 'text-align');
$purifier = new HTMLPurifier($config);

That's the first step. If you want to disallow anything but center as in that thread, you would change the CSS AttrDef for text-align:

$css = $purifier->getCSSDefinition();
$css->info['text-align'] = new HTMLPurifier_AttrDef_Enum(array('center'));

// should allow text-align:center but not text-align:right or the likes:
$purifier->purify(/* ... */);

OTHER TIPS

The default configuration of HTML Purifier will not strip centered text.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top