Page 1 of 1

htmlpurifier lacking documentation/examples or?

Posted: Sun Feb 01, 2009 8:18 am
by jmut
Hi,
I am sure htmlpurifier is a great tool but it's like 20min now and I cannot find code example which I can copy/paste and adjust white list of tags/attributes that are allowed. I think people mainly would love htmlpurifier as is perfect tool to strip wysiwyg nasty stuff - just as advertised on first page. Is there really no example of this main thingy or I have to dig through documeation to build this.
I see one docs/examples/basic.php but it's really basic and there should be mooore examplese :)
Cheers

Re: htmlpurifier lacking documentation/examples or?

Posted: Sun Feb 01, 2009 9:21 am
by jmut
This is what I came up with in case someone is interested.

Code: Select all

require_once 'htmlpurifier/library/HTMLPurifier.auto.php';
$config = HTMLPurifier_Config::createDefault();
$config->set('Core', 'Encoding', 'UTF-8'); // replace with your encoding
$config->set('HTML', 'Doctype', 'XHTML 1.0 Transitional'); // replace with your doctype
 
$allowedHtml = '
    a[rel|rev|charset|hreflang|tabindex|accesskey|type|name|href|target|title|class|onfocus|onblur]
    strong,b,em,i,strike,u,
    p[align],ol[type|compact],ul,li,br,img[src|width|height|alt|title],
    sub,sup,
    blockquote,table[border|cellspacing|cellpadding|width|height|align|summary|bgcolor|background|bordercolor],
    tr[rowspan|width|height|align|valign|bgcolor|background|bordercolor],tbody,thead,tfoot,
    td[colspan|rowspan|width|height|align|valign|bgcolor|background|bordercolor|scope]
    th[colspan|rowspan|width|height|align|valign|scope],
    caption,div, span, code, pre,address, h1, h2, h3, h4, h5, h6, hr[size|noshade],
    font[face|size|color],dd,dl,dt,cite,abbr,acronym,del[datetime|cite],ins[datetime|cite],
    button,col[align|char|charoff|span|valign|width],colgroup[align|char|charoff|span|valign|width],
    dfn,fieldset, kbd,label[for],legend,optgroup[label|disabled],option[disabled|label|selected|value],
    q[cite],,small,
    textarea[cols|rows|disabled|name|readonly],tt,var,big';
 
$config->set('HTML', 'Allowed', $allowedHtml);
$config->set('HTML', 'AllowedAttributes', '*.style,*.id,*.title,*.class');
$config->set('Attr', 'EnableID', true);
$purifier = new HTMLPurifier($config);



~90 testcases are failing but hopefully it will work out :D