【问题标题】:Html purifier clears p taghtml净化器清除p标签
【发布时间】:2011-08-18 08:47:44
【问题描述】:

由于某种原因,html 净化器清除了 p 标签。当 p 在 span 标签内时会发生这种情况。 例如:

<span class=\"large gray content_text article_text\">
<p>111111</p>
<p>222222</p>
<p>333333</p>
</span>

输出:

<span>111111

2222222

3333333</span>

我的 htmlpurifier 配置:

$config = HTMLPurifier_Config::createDefault();
$config -> set('Core.Encoding', 'UTF-8');
$config -> set('HTML.Doctype', 'XHTML 1.0 Transitional');
$config -> set('HTML.TidyLevel','none');
$config -> set('HTML.Allowed', 'p, a[href|rel], span[style], img[src|style], object[height|width|data], param[name|value|allowscriptaccess|allowfullscreen|height|width], br, strong, em');
$config -> set('CSS.AllowedProperties', 'font-weight, font-style, text-decoration, color, width, height');
$config -> set('HTML.SafeObject', 'true');
$config -> set('Output.FlashCompat', 'true');
$config -> set('HTML.FlashAllowFullScreen', 'true');
$schemes = array('http' => true, 'https' => true);
$config -> set('URI.AllowedSchemes', $schemes);
$purifier = new HTMLPurifier($config);
$content = $purifier -> purify($content);

【问题讨论】:

  • 你不需要在 标签中转义引号,对吗?
  • 首先&lt;p&gt;&lt;span&gt;里面这个格式是错误的。您不能在内联元素&lt;span&gt; 内定义块级元素&lt;p&gt;。 W3c 不会对此进行验证。
  • 哦,我在 span 上做了stripslashes。只是从仍然存在斜杠的旧示例中复制粘贴。

标签: php html w3c-validation htmlpurifier


【解决方案1】:

&lt;span&gt; 是内联元素,将块级&lt;p&gt; 标签放入其中是不正确的。

使用&lt;div&gt; 而不是&lt;span&gt;

【讨论】:

  • 我不这样做。是用户输入。我尝试清除它,但保留一些文本格式。
  • @inwoker 你可以尝试使用 Core.EscapeInvalidTags 然后替换 <p>

    等等,但这不是一个好习惯

【解决方案2】:

嗯,HTML净化器应该有输出:

<span class="large gray content_text article_text"></span>
<p><span class="large gray content_text article_text">111111</span></p>
<p><span class="large gray content_text article_text">222222</span></p>
<p><span class="large gray content_text article_text">333333</span></p>
<span class="large gray content_text article_text"></span>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-02-26
    • 2022-01-19
    • 2017-06-06
    • 2015-10-16
    • 1970-01-01
    • 2022-12-03
    • 1970-01-01
    相关资源
    最近更新 更多