Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTMLPurifier allow centered text

Tags:

htmlpurifier

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

Thanks!

like image 850
Abela Avatar asked May 29 '26 23:05

Abela


1 Answers

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(/* ... */);
like image 158
pinkgothic Avatar answered Jun 02 '26 19:06

pinkgothic



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!