--- htmlpurifier.module 2010-06-04 09:44:15.000000000 -0700 +++ htmlpurifier.module (working copy) @@ -121,8 +121,39 @@ function _htmlpurifier_process($text, $f _htmlpurifier_load(); $config = _htmlpurifier_get_config($format); + + // If ExtractStyleBlocks is enabled, we'll need to do a bit more for CSSTidy + $config_extractstyleblocks = $config->get('Filter.ExtractStyleBlocks'); + + // Maybe this works if CSSTidy is at root? CSSTidy could be other places though + if ($config_extractstyleblocks == true) { + // If CSSTidy module is installed, it should have a copy we can use + $csstidy_path = drupal_get_path('module', 'csstidy') .'/csstidy'; + + // Some future-proofing for library path + if (function_exists('libraries_get_path')) { + $csstidy_library = libraries_get_path('csstidy'); + if (file_exists("$csstidy_library/class.csstidy.php")) { + $csstidy_path = $csstidy_library; + } + } + + // Load CSSTidy if we can find it + if (file_exists("$csstidy_path/class.csstidy.php")) { + require_once "$csstidy_path/class.csstidy.php"; + } + } + $purifier = new HTMLPurifier($config); $ret = $purifier->purify($text); + + // Add CSSTidy extraced StyleBlocks if needed + if ($config_extractstyleblocks == true) { + $styles = $purifier->context->get('StyleBlocks'); + foreach ($styles as $style) { + $ret = '' . $ret; + } + } if ($cache) cache_set($cid, $ret, 'cache_htmlpurifier', CACHE_PERMANENT);