createGlobalAttrs(); $httpUriBuilder = GeneralUtility::makeInstance(UriAttrValueBuilder::class) ->allowSchemes('http', 'https'); $behavior = GeneralUtility::makeInstance(Behavior::class) ->withTags( (new Behavior\Tag('a', Behavior\Tag::ALLOW_CHILDREN)) ->addAttrs(...$globalAttrs) ->addAttrs(...$this->createAttrs('rel', 'target')) ->addAttrs( (new Behavior\Attr('href')) ->withValues(...$httpUriBuilder->getValues()), ), (new Behavior\Tag('b', Behavior\Tag::ALLOW_CHILDREN)) ->addAttrs(...$globalAttrs), (new Behavior\Tag('br')) ->addAttrs(...$globalAttrs), (new Behavior\Tag('div', Behavior\Tag::ALLOW_CHILDREN)) ->addAttrs(...$globalAttrs), (new Behavior\Tag('em', Behavior\Tag::ALLOW_CHILDREN)) ->addAttrs(...$globalAttrs), (new Behavior\Tag('i', Behavior\Tag::ALLOW_CHILDREN)) ->addAttrs(...$globalAttrs), (new Behavior\Tag('li', Behavior\Tag::ALLOW_CHILDREN)) ->addAttrs(...$globalAttrs), (new Behavior\Tag('span', Behavior\Tag::ALLOW_CHILDREN)) ->addAttrs(...$globalAttrs), (new Behavior\Tag('strong', Behavior\Tag::ALLOW_CHILDREN)) ->addAttrs(...$globalAttrs), (new Behavior\Tag('ul', Behavior\Tag::ALLOW_CHILDREN)) ->addAttrs(...$globalAttrs) ); $visitor = GeneralUtility::makeInstance(CommonVisitor::class, $behavior); return GeneralUtility::makeInstance(Sanitizer::class, $behavior, $visitor); } /** * @return Behavior\Attr[] */ protected function createGlobalAttrs(): array { // https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes $attrs = $this->createAttrs( 'class', 'role', 'tabindex', 'title', ); $attrs[] = new Behavior\Attr('aria-', Behavior\Attr::NAME_PREFIX); $attrs[] = new Behavior\Attr('data-', Behavior\Attr::NAME_PREFIX); return $attrs; } /** * @return Behavior\Attr[] */ protected function createAttrs(string ...$names): array { return array_map( static function (string $name): Behavior\Attr { return new Behavior\Attr($name); }, $names ); } }