Html净化器清除p标签
由于某种原因,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);
For some reason html purifier clears p tags. It happens when p is inside of span tags.
For example:
<span class=\"large gray content_text article_text\">
<p>111111</p>
<p>222222</p>
<p>333333</p>
</span>
Output:
<span>111111
2222222
3333333</span>
My htmlpurifier config:
$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);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是一个内联元素,在其中放置块级
标签是不正确的。
使用
而不是
。
<span>
is an inline element, it's incorrect to put block level<p>
tags inside of it.Use
<div>
instead of<span>
.嗯,HTML Purifier 应该有输出:
Hmm, HTML Purifier should have output: