htmlpurifier with an html5 doctype

2019-02-16 21:48发布

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?

6条回答
女痞
2楼-- · 2019-02-16 21:58

I don't think it supports Html5 yet. Maybe suggest it to them or create a patch for it if you really need it..

查看更多
Rolldiameter
3楼-- · 2019-02-16 22:05

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

查看更多
甜甜的少女心
4楼-- · 2019-02-16 22:10

No, HTML Purifier does not currently support HTML 5.

查看更多
叛逆
5楼-- · 2019-02-16 22:11

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.

查看更多
爷、活的狠高调
6楼-- · 2019-02-16 22:17

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

查看更多
欢心
7楼-- · 2019-02-16 22:19

Found this when searching for html5 implementation/use of htmlPurify: https://github.com/xemlock/htmlpurifier-html5

查看更多
登录 后发表回答