예제 #1
0
 /**
  * Normalize attribute values.
  *
  * @param string        $source
  * @param HtmlTokenizer $tokenizer
  * @return mixed
  */
 protected function normalizeAttributes($source, HtmlTokenizer $tokenizer)
 {
     $result = '';
     foreach ($tokenizer->parse($source) as $token) {
         if (empty($token[HtmlTokenizer::TOKEN_ATTRIBUTES])) {
             $result .= $tokenizer->compile($token);
             continue;
         }
         $attributes = [];
         foreach ($token[HtmlTokenizer::TOKEN_ATTRIBUTES] as $attribute => $value) {
             if (in_array($attribute, $this->options['attributes']['trim'])) {
                 $value = trim($value);
             }
             if (empty($value) && in_array($attribute, $this->options['attributes']['drop'])) {
                 //Empty value
                 continue;
             }
             $attributes[$attribute] = $value;
         }
         $token[HtmlTokenizer::TOKEN_ATTRIBUTES] = $attributes;
         $result .= $tokenizer->compile($token);
     }
     return $result;
 }