【问题标题】:HtmlPurifier add unsupported stylesheet for one tagHtmlPurifier 为一个标签添加不支持的样式表
【发布时间】:2015-02-04 08:26:04
【问题描述】:

我使用 HTMLPurifier 4.6.0 过滤 HTML。我的 HTML 有这一行:

<pre style="overflow-x: scroll; word-wrap: normal; white-space: pre;">

提交后被截断:

<pre style="white-space: pre;">

我只想允许

 样式“overflow-x:scroll”和“word-wrap:normal”。

我找到了这个页面http://htmlpurifier.org/docs/enduser-customize.html并尝试了:

    $config->set('HTML.DefinitionID', 'enduser-customize.html');
    $config->set('HTML.DefinitionRev', 1);
    $config->set('Cache.DefinitionImpl', null); // TODO: remove this later!
    if ($def = $config->maybeGetRawHTMLDefinition()) {
        $def->addAttribute('pre', 'style', 'overflow-x');
    }

我在设置addAttribute() 时遇到问题。有人可以在这里帮助我吗?谢谢!

【问题讨论】:

    标签: htmlpurifier


    【解决方案1】:

    我找到了使用此设置的解决方案:

    $css = $config->getCSSDefinition();
    $css->info['overflow-x'] = new HTMLPurifier_AttrDef_Enum(array('scroll'));
    $css->info['word-wrap'] = new HTMLPurifier_AttrDef_Enum(array('normal'));
    

    【讨论】:

      猜你喜欢
      • 2023-04-01
      • 2020-10-26
      • 2013-02-13
      • 1970-01-01
      • 2012-08-12
      • 1970-01-01
      • 2012-03-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多