带有 html5 文档类型的 htmlpurifier
是否可以让 htmlpurifier 使用 html5 文档类型?
文档此处指出您可以使用以下内容更改文档类型和编码:
<?php
require_once '/path/to/htmlpurifier/library/HTMLPurifier.auto.php';
$config = HTMLPurifier_Config::createDefault();
$config->set('Core', 'Encoding', 'ISO-8859-1'); // replace with your encoding
$config->set('HTML', 'Doctype', 'HTML 4.01 Transitional'); // replace with your doctype
$purifier = new HTMLPurifier($config);
$clean_html = $purifier->purify($dirty_html);
?>
但随后在安装说明中这里指出支持的文档类型是:
256 Other supported doctypes include:
257
258 * HTML 4.01 Strict
259 * HTML 4.01 Transitional
260 * XHTML 1.0 Strict
261 * XHTML 1.0 Transitional
262 * XHTML 1.1
是否可以执行以下操作以允许 html5 doctype?
<?php
require_once '/path/to/htmlpurifier/library/HTMLPurifier.auto.php';
$config = HTMLPurifier_Config::createDefault();
$config->set('Core', 'Encoding', 'UTF-8'); // replace with your encoding
$config->set('HTML', 'Doctype', 'html5'); // replace with your doctype
$purifier = new HTMLPurifier($config);
$clean_html = $purifier->purify($dirty_html);
?>
或者还有别的办法吗?
Is it possible to have htmlpurifier use the html5 doctype?
The documentation here states that you can change the doctype and encoding with the following:
<?php
require_once '/path/to/htmlpurifier/library/HTMLPurifier.auto.php';
$config = HTMLPurifier_Config::createDefault();
$config->set('Core', 'Encoding', 'ISO-8859-1'); // replace with your encoding
$config->set('HTML', 'Doctype', 'HTML 4.01 Transitional'); // replace with your doctype
$purifier = new HTMLPurifier($config);
$clean_html = $purifier->purify($dirty_html);
?>
but then in the install instructions here states that the supported doctypes are:
256 Other supported doctypes include:
257
258 * HTML 4.01 Strict
259 * HTML 4.01 Transitional
260 * XHTML 1.0 Strict
261 * XHTML 1.0 Transitional
262 * XHTML 1.1
Is it possible to do the following to allow html5 doctype?
<?php
require_once '/path/to/htmlpurifier/library/HTMLPurifier.auto.php';
$config = HTMLPurifier_Config::createDefault();
$config->set('Core', 'Encoding', 'UTF-8'); // replace with your encoding
$config->set('HTML', 'Doctype', 'html5'); // replace with your doctype
$purifier = new HTMLPurifier($config);
$clean_html = $purifier->purify($dirty_html);
?>
Or is there another way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
不,HTML Purifier 目前不支持 HTML 5。
No, HTML Purifier does not currently support HTML 5.
这仍然是真的吗? 此页面似乎暗示此信息已过时...
Is this still true? This page seems to imply this information is outdated...
至于2017年秋季好像还没有官方支持。
...但是您可以在此处检查 HTML5 的某种解决方法:
https://github.com/kennberg/php-htmlpurfier-html5
和另一个:https://github.com/xemlock/htmlpurifier-html5
As for fall of 2017 seems there are still no official support.
...but you can check some kind of workaround for HTML5 here:
https://github.com/kennberg/php-htmlpurfier-html5
and another one: https://github.com/xemlock/htmlpurifier-html5
这是一个重新设计的 HTML5 版本的 html purifier - 在搜索 html5 实现/使用 htmlPurify 时发现了这个: https:/ /github.com/xemlock/htmlpurifier-html5
Here's a reworked HTML5 version of html purifier - found this when searching for html5 implementation/use of htmlPurify: https://github.com/xemlock/htmlpurifier-html5
我认为它还不支持 Html5。如果您确实需要的话,也许可以向他们建议或为其创建补丁。
I don't think it supports Html5 yet. Maybe suggest it to them or create a patch for it if you really need it..
http://htmlpurifier.org/docs/enduser-customize.html
它仍然没有不支持 HTML5 DOCTYPE,但您可以使用上面的指南指定要添加的标签。
http://htmlpurifier.org/docs/enduser-customize.html
It still doesn't support HTML5 DOCTYPE but you can specify what tags you want to add using the guide above.
不,HTML Purifier 目前不支持 HTML 5。
$config->set('HTML.Doctype', 'HTML 4.01 Transitional');
No, HTML Purifier does not currently support HTML 5.
$config->set('HTML.Doctype', 'HTML 4.01 Transitional');