带有 html5 文档类型的 htmlpurifier

发布于 2024-10-09 11:37:57 字数 1420 浏览 7 评论 0原文

是否可以让 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

ヤ经典坏疍 2024-10-16 11:37:57

不,HTML Purifier 目前不支持 HTML 5。

No, HTML Purifier does not currently support HTML 5.

赴月观长安 2024-10-16 11:37:57

这仍然是真的吗? 此页面似乎暗示此信息已过时...

Is this still true? This page seems to imply this information is outdated...

意中人 2024-10-16 11:37:57

至于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

濫情▎り 2024-10-16 11:37:57

这是一个重新设计的 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

烟花易冷人易散 2024-10-16 11:37:57

我认为它还不支持 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..

上课铃就是安魂曲 2024-10-16 11:37:57

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.

甜妞爱困 2024-10-16 11:37:57

不,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');

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文