include/HTMLPurifier/standalone/HTMLPurifier/Filter/ExtractStyleBlocks.php

Show: inherited
Table of Contents

\HTMLPurifier_Filter_ExtractStyleBlocks

Package: SugarCRM

This filter extracts <style> blocks from input HTML, cleans them up using CSSTidy, and then places them in $purifier->context->get('StyleBlocks') so they can be used elsewhere in the document.

Sometimes, a little ad-hoc fixing of HTML has to be done before it gets sent through HTML Purifier: you can use filters to acheive this effect. For instance, YouTube videos can be preserved using this manner. You could have used a decorator for this task, but PHP's support for them is not terribly robust, so we're going to just loop through the filters.

Filters should be exited first in, last out. If there are three filters, named 1, 2 and 3, the order of execution should go 1->preFilter, 2->preFilter, 3->preFilter, purify, 3->postFilter, 2->postFilter, 1->postFilter.

Parent(s)
\HTMLPurifier_Filter
Note
See tests/HTMLPurifier/Filter/ExtractStyleBlocksTest.php for sample usage.  
Note
This filter can also be used on stylesheets not included in the document--something purists would probably prefer. Just directly call HTMLPurifier_Filter_ExtractStyleBlocks->cleanCSS()  

Properties

Propertyprivate  $_styleMatches= 'array()'
Default valuearray()Details
Type
n/a
Propertyprivate  $_tidy= ''
Details
Type
n/a
Propertypublic  $name= ''ExtractStyleBlocks''

Name of the filter for identification purposes

Default value'ExtractStyleBlocks'Details
Type
n/a

Methods

methodpublic__construct( ) : void

methodpubliccleanCSS( \$css $css, \$config $config, \$context $context ) : \Cleaned

Takes CSS (the stuff found in