/** * @param SupervisorInterface $supervisor * @param string $name * @param string|array $source String content or array of html tokens. * @param HtmlTokenizer $tokenizer Html tokens source. */ public function __construct(SupervisorInterface $supervisor, $name, $source = [], HtmlTokenizer $tokenizer = null) { $this->supervisor = $supervisor; $this->name = $name; if (empty($tokenizer)) { $tokenizer = new HtmlTokenizer(); } if (is_string($source)) { $source = $tokenizer->parse($source); } $this->parseTokens($source); }
/** * 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; }