Use default configuration when resetting; prevents zombie defaults for encodings...
[htmlpurifier.git] / library / HTMLPurifier / Injector / RemoveEmpty.php
blobd85ca97d92349abb77a6f35719f86169bedd97ba
1 <?php
3 class HTMLPurifier_Injector_RemoveEmpty extends HTMLPurifier_Injector
6 private $context, $config;
8 public function prepare($config, $context) {
9 parent::prepare($config, $context);
10 $this->config = $config;
11 $this->context = $context;
12 $this->attrValidator = new HTMLPurifier_AttrValidator();
15 public function handleElement(&$token) {
16 if (!$token instanceof HTMLPurifier_Token_Start) return;
17 $next = false;
18 for ($i = $this->inputIndex + 1, $c = count($this->inputTokens); $i < $c; $i++) {
19 $next = $this->inputTokens[$i];
20 if ($next instanceof HTMLPurifier_Token_Text && $next->is_whitespace) continue;
21 break;
23 if (!$next || ($next instanceof HTMLPurifier_Token_End && $next->name == $token->name)) {
24 if ($token->name == 'colgroup') return;
25 $this->attrValidator->validateToken($token, $this->config, $this->context);
26 $token->armor['ValidateAttributes'] = true;
27 if (isset($token->attr['id']) || isset($token->attr['name'])) return;
28 $token = $i - $this->inputIndex + 1;
29 for ($b = $this->inputIndex - 1; $b > 0; $b--) {
30 $prev = $this->inputTokens[$b];
31 if ($prev instanceof HTMLPurifier_Token_Text && $prev->is_whitespace) continue;
32 break;
34 // This is safe because we removed the token that triggered this.
35 $this->rewind($b - 1);
36 return;
42 // vim: et sw=4 sts=4