1
0
mirror of https://github.com/ezyang/htmlpurifier.git synced 2025-07-31 19:30:21 +02:00

[3.0.0] Fully implement CSS extraction and cleaning. See NEWS for more information, it is now a Filter.

- Some Lexer things were moved around

git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@1469 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
Edward Z. Yang
2007-12-12 21:46:30 +00:00
parent 831f552ec5
commit 5b3431d889
9 changed files with 231 additions and 92 deletions

View File

@@ -79,14 +79,6 @@ It is not necessary and will have no effect for PHP 4.
This directive has been available since 2.1.0.
');
HTMLPurifier_ConfigSchema::define(
'HTML', 'ExtractStyleBlocks', false, 'bool', '
This directive enables extraction of <code>style</code> tags contents so
that they can be incorporated in the <code>head</code> of the document,
after sufficient validation.
This directive has been available since 3.0.0.
');
/**
* Forgivingly lexes HTML (SGML-style) markup into tokens.
*
@@ -346,34 +338,6 @@ class HTMLPurifier_Lexer
// represent non-SGML characters (horror, horror!)
$html = HTMLPurifier_Encoder::cleanUTF8($html);
if ($config->get('HTML', 'ExtractStyleBlocks')) {
// extract <style> CSS blocks
$html = $this->extractStyleBlocks($html, $config, $context);
}
return $html;
}
private $_styleMatches = array();
/**
* Save the contents of CSS blocks to style matches
*/
protected function styleCallback($matches) {
$this->_styleMatches[] = $matches[1];
}
/**
* Removes inline <style> tags from HTML, saves them for later use
* @todo Extend to indicate non-text/css style blocks
*/
public function extractStyleBlocks($html, $config, $context) {
$html = preg_replace_callback('#<style(?:\s.*)?>(.+)</style>#isU', array($this, 'styleCallback'), $html);
$style_blocks = $this->_styleMatches;
$this->_styleMatches = array(); // reset
// this is a persistent context, so we have to overwrite it with every call
if ($context->exists('StyleBlocks')) $context->destroy('StyleBlocks');
$context->register('StyleBlocks', $style_blocks);
return $html;
}