htmlpurifier如何允许borderRadius?
我发现了这一点,但它似乎不适用于当前版本的htmlpurifier,也许它们改变了您添加自己的CSS的方式?
http://htmlpurifier.org/phorum/read.php?2,6154,6154
$config = HTMLPurifier_Config::createDefault();
// add some custom CSS3 properties
$css_definition = $config->getDefinition('CSS');
$border_radius =
$info['border-top-left-radius'] =
$info['border-top-right-radius'] =
$info['border-bottom-left-radius'] =
$info['border-bottom-right-radius'] =
new HTMLPurifier_AttrDef_CSS_Composite(array(
new HTMLPurifier_AttrDef_CSS_Length('0'),
new HTMLPurifier_AttrDef_CSS_Percentage(true)
));
$info['border-radius'] = new HTMLPurifier_AttrDef_CSS_Multiple($border_radius);
// wrap all new attr-defs with decorator that handles !important
$allow_important = $config->get('CSS.AllowImportant');
foreach ($info as $k => $v) {
$css_definition->info[$k] = new HTMLPurifier_AttrDef_CSS_ImportantDecorator($v, $allow_important);
}
$html_purifier = new HTMLPurifier($config);
最佳答案
我分叉了原始存储库,并在净化功能中添加了边框半径功能,请在此处找到代码
https://github.com/msvensson82/htmlpurifier
如果您想修改自己的目录而不是获取我的仓库,我基本上只是将其添加到CSSDefinition.php文件中。
// border-radius
$border_radius =
$this->info['border-top-left-radius'] =
$this->info['border-top-right-radius'] =
$this->info['border-bottom-left-radius'] =
$this->info['border-bottom-right-radius'] = new HTMLPurifier_AttrDef_CSS_Composite(array(
new HTMLPurifier_AttrDef_CSS_Length('0'),
new HTMLPurifier_AttrDef_CSS_Percentage(true)
));
$this->info['border-radius'] = new HTMLPurifier_AttrDef_CSS_Multiple($border_radius);