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;
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;
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;
34 // This is safe because we removed the token that triggered this.
35 $this->rewind($b - 1);