Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

htmlpurifier with an html5 doctype

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?

like image 833
Jason Avatar asked Dec 30 '10 21:12

Jason


1 Answers

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

like image 139
Jacob Kruger Avatar answered Oct 11 '22 14:10

Jacob Kruger