]> git.wh0rd.org - tt-rss.git/blob - lib/htmlpurifier/library/HTMLPurifier/Injector/RemoveEmpty.php
strip_tags_long: use htmlpurifier to properly reformat html content
[tt-rss.git] / lib / htmlpurifier / library / HTMLPurifier / Injector / RemoveEmpty.php
1 <?php
2
3 class HTMLPurifier_Injector_RemoveEmpty extends HTMLPurifier_Injector
4 {
5
6 private $context, $config;
7
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();
13 }
14
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;
22 }
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;
33 }
34 // This is safe because we removed the token that triggered this.
35 $this->rewind($b - 1);
36 return;
37 }
38 }
39
40 }
41
42 // vim: et sw=4 sts=4