Abela
Abela

Reputation: 1233

HTMLPurifier allow centered text

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

Thanks!

Upvotes: 3

Views: 1162

Answers (2)

pinkgothic
pinkgothic

Reputation: 6179

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(/* ... */);

Upvotes: 3

Edward Z. Yang
Edward Z. Yang

Reputation: 26742

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

Upvotes: 0

Related Questions