4 * Injector that removes spans with no attributes
6 class HTMLPurifier_Injector_RemoveSpansWithoutAttributes
extends HTMLPurifier_Injector
11 public $name = 'RemoveSpansWithoutAttributes';
16 public $needed = array('span');
19 * @type HTMLPurifier_AttrValidator
21 private $attrValidator;
24 * Used by AttrValidator.
25 * @type HTMLPurifier_Config
30 * @type HTMLPurifier_Context
34 public function prepare($config, $context)
36 $this->attrValidator
= new HTMLPurifier_AttrValidator();
37 $this->config
= $config;
38 $this->context
= $context;
39 return parent
::prepare($config, $context);
43 * @param HTMLPurifier_Token $token
45 public function handleElement(&$token)
47 if ($token->name
!== 'span' ||
!$token instanceof HTMLPurifier_Token_Start
) {
51 // We need to validate the attributes now since this doesn't normally
52 // happen until after MakeWellFormed. If all the attributes are removed
53 // the span needs to be removed too.
54 $this->attrValidator
->validateToken($token, $this->config
, $this->context
);
55 $token->armor
['ValidateAttributes'] = true;
57 if (!empty($token->attr
)) {
62 while ($this->forwardUntilEndToken($i, $current, $nesting)) {
65 if ($current instanceof HTMLPurifier_Token_End
&& $current->name
=== 'span') {
66 // Mark closing span tag for deletion
67 $current->markForDeletion
= true;
68 // Delete open span tag
74 * @param HTMLPurifier_Token $token
76 public function handleEnd(&$token)
78 if ($token->markForDeletion
) {