HTML filter that is HTML5 compliant

后端 未结 5 1131
轻奢々
轻奢々 2020-12-07 16:24

Is there a simple approach to add a HTML5 ruleset for HTMLPurifier?

HP can be configured to recognize new tags with:

// setup configurable HP instanc         


        
5条回答
  •  日久生厌
    2020-12-07 17:18

    I know this topic is really old, but since it's still relevant, I decided to respond. Especially when the landscape has changed since the question was originally asked.

    You can use https://github.com/xemlock/htmlpurifier-html5 which extends HTML Purifier with spec compliant definitions of HTML5 elements and attributes.

    The usage is almost the same as the original HTML Purifier, you just need to replace HTMLPurifier_Config with HTMLPurifier_HTML5Config:

    $config = HTMLPurifier_HTML5Config::createDefault();
    $purifier = new HTMLPurifier($config);
    
    $clean_html5 = $purifier->purify($dirty_html5);
    

    Disclaimer: I'm the author of the extension.

提交回复
热议问题