summaryrefslogtreecommitdiff
path: root/lib/htmlpurifier/library/HTMLPurifier/Injector/RemoveEmpty.php
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2009-06-22 13:56:49 +0400
committerAndrew Dolgov <[email protected]>2009-06-22 13:56:49 +0400
commitf45a286b8d62f710b519a98c7d4b75a0c34d5d10 (patch)
tree0c310b7b9d44e12fac1cd11e1563c4cef9b5eab2 /lib/htmlpurifier/library/HTMLPurifier/Injector/RemoveEmpty.php
parent5c4461432c290ad4863fd7dc4107121db59b298c (diff)
strip_tags_long: use htmlpurifier to properly reformat html content
Diffstat (limited to 'lib/htmlpurifier/library/HTMLPurifier/Injector/RemoveEmpty.php')
-rwxr-xr-xlib/htmlpurifier/library/HTMLPurifier/Injector/RemoveEmpty.php42
1 files changed, 42 insertions, 0 deletions
diff --git a/lib/htmlpurifier/library/HTMLPurifier/Injector/RemoveEmpty.php b/lib/htmlpurifier/library/HTMLPurifier/Injector/RemoveEmpty.php
new file mode 100755
index 000000000..d85ca97d9
--- /dev/null
+++ b/lib/htmlpurifier/library/HTMLPurifier/Injector/RemoveEmpty.php
@@ -0,0 +1,42 @@
+<?php
+
+class HTMLPurifier_Injector_RemoveEmpty extends HTMLPurifier_Injector
+{
+
+ private $context, $config;
+
+ public function prepare($config, $context) {
+ parent::prepare($config, $context);
+ $this->config = $config;
+ $this->context = $context;
+ $this->attrValidator = new HTMLPurifier_AttrValidator();
+ }
+
+ public function handleElement(&$token) {
+ if (!$token instanceof HTMLPurifier_Token_Start) return;
+ $next = false;
+ for ($i = $this->inputIndex + 1, $c = count($this->inputTokens); $i < $c; $i++) {
+ $next = $this->inputTokens[$i];
+ if ($next instanceof HTMLPurifier_Token_Text && $next->is_whitespace) continue;
+ break;
+ }
+ if (!$next || ($next instanceof HTMLPurifier_Token_End && $next->name == $token->name)) {
+ if ($token->name == 'colgroup') return;
+ $this->attrValidator->validateToken($token, $this->config, $this->context);
+ $token->armor['ValidateAttributes'] = true;
+ if (isset($token->attr['id']) || isset($token->attr['name'])) return;
+ $token = $i - $this->inputIndex + 1;
+ for ($b = $this->inputIndex - 1; $b > 0; $b--) {
+ $prev = $this->inputTokens[$b];
+ if ($prev instanceof HTMLPurifier_Token_Text && $prev->is_whitespace) continue;
+ break;
+ }
+ // This is safe because we removed the token that triggered this.
+ $this->rewind($b - 1);
+ return;
+ }
+ }
+
+}
+
+// vim: et sw=4 sts=4