htmlpurifier with an html5 doctype
Asked Answered
E

7

13

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?

Excruciation answered 30/12, 2010 at 21:10 Comment(0)
E
13

No, HTML Purifier does not currently support HTML 5.

Epic answered 31/12, 2010 at 0:19 Comment(13)
Are you planning to add support for HTML 5?Kamilahkamillah
Yes, but in the sense of "Uh, you will have to wait indefinitely long until I get around to doing it."Epic
I saw this post htmlpurifier.org/phorum/read.php?2,6169,6169 which is dated Feb 1, 2012 which says HTML5 is still not supported. It's now Nov, 2012. I was hoping if support for html5 has been added recently?Trouveur
Nope, two years later, and no progress has been made.Epic
The year is 2013. Winters have been getting more and more harsh of late, as the cold strikes deeper and longer across Europe. Heavy rains are more and more common, and it's starting to take a toll on crop growth. Yet another problem compounded on an already troubled economic climate. I can see the dispair on peoples faces as I walk down the street. That is, when I can see those faces. Most people look down at the floor as I walk by. And yet.. For no apparant reason, I feel optimism bubbling up withing me. I write code - I need HTMLPurifier and - perhaps, just perhaps.. it now supports HTML5?Misuse
The year is now 2014. Maybe this year htmlpurifier will support html5?Smoko
How about 2017?Dost
I finished my PhD... but still no HTML5 support for HTML Purifier :)Epic
We're past half of 2018, HTML5 is almost the only thing we use nowadays. Why don't you simply state HTML5 won't ever be supported on HTML Purifier and start sunsetting it as "won't get new updates"? This way people will stop searching and asking for that - and maybe move onto Tidy instead. Otherwise, you could officially suggest the usage of extension packages such as xemlock's.Pneumonic
2019 begin... driver-less cars, china on the moon. HTML Purifier... year++Bolden
2020 middle of spring... entire world is isolated at their homes due to coronavirus, borders are closed, one of the hugest economy crises is knocking the door. But html purifier still doesn't support html5 out of the box.Tombac
2021, 1 year into the pandemic, luckily vaccines are on the way. But even without a vaccine, htmlpurifier is immune to html5.Inattentive
Ezyang says he won't support html5 and recommends to switch to a fork (xemlock one): github.com/ezyang/htmlpurifier/issues/160Interlingua
E
5

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

Eider answered 5/6, 2012 at 20:42 Comment(1)
HTML Purifier comes with three bundled DOM parsers implementations. The link above points to one of them. And this implementation does not contain any definitions of HTML5 elements which HTML Purifier can later use for filtering - it's only for building DOM-structure from string input.Boardman
Z
3

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

Zoosperm answered 20/11, 2017 at 17:32 Comment(0)
B
3

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

Babbitt answered 5/9, 2018 at 15:48 Comment(1)
A link to a solution is welcome, but please ensure your answer is useful without it: add context around the link so your fellow users will have some idea what it is and why it’s there, then quote the most relevant part of the page you're linking to in case the target page is unavailable. Answers that are little more than a link may be deleted.Demijohn
V
1

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

Visible answered 31/12, 2010 at 0:24 Comment(0)
L
0

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.

Littlest answered 13/4, 2016 at 23:9 Comment(0)
A
0

No, HTML Purifier does not currently support HTML 5.

$config->set('HTML.Doctype', 'HTML 4.01 Transitional');

Actuary answered 29/4, 2023 at 8:38 Comment(1)
Please, check formattingTankersley

© 2022 - 2024 — McMap. All rights reserved.