4 * Injector that removes spans with no attributes
6 class HTMLPurifier_Injector_RemoveSpansWithoutAttributes extends HTMLPurifier_Injector
8 public $name = 'RemoveSpansWithoutAttributes';
9 public $needed = array('span');
11 private $attrValidator;
14 * Used by AttrValidator
19 public function prepare($config, $context) {
20 $this->attrValidator = new HTMLPurifier_AttrValidator();
21 $this->config = $config;
22 $this->context = $context;
23 return parent::prepare($config, $context);
26 public function handleElement(&$token) {
27 if ($token->name !== 'span' || !$token instanceof HTMLPurifier_Token_Start) {
31 // We need to validate the attributes now since this doesn't normally
32 // happen until after MakeWellFormed. If all the attributes are removed
33 // the span needs to be removed too.
34 $this->attrValidator->validateToken($token, $this->config, $this->context);
35 $token->armor['ValidateAttributes'] = true;
37 if (!empty($token->attr)) {
42 $spanContentTokens = array();
43 while ($this->forwardUntilEndToken($i, $current, $nesting)) {}
45 if ($current instanceof HTMLPurifier_Token_End && $current->name === 'span') {
46 // Mark closing span tag for deletion
47 $current->markForDeletion = true;
48 // Delete open span tag
53 public function handleEnd(&$token) {
54 if ($token->markForDeletion) {