Skip to content
This repository has been archived by the owner on May 23, 2024. It is now read-only.

Remove span #40

Open
zecka opened this issue May 27, 2020 · 3 comments
Open

Remove span #40

zecka opened this issue May 27, 2020 · 3 comments

Comments

@zecka
Copy link

zecka commented May 27, 2020

Any way to remove span tag when used 'basic' extension ?

@zecka
Copy link
Author

zecka commented May 27, 2020

Finaly I create a custom extension who extends BasicExtension

// custom-extension.php
use HtmlSanitizer\Extension\Basic\BasicExtension;
class CustomExtension extends BasicExtension
{
    public function getName(): string
    {
        return 'custom';
    }
    public function createNodeVisitors(array $config = []): array
    {
        $array = parent::createNodeVisitors($config);
        unset($array['span']);
        return $array;
    }
}
// demo.php
require 'custom-extension.php';
$builder = HtmlSanitizer\SanitizerBuilder::createDefault();
$builder->registerExtension(new CustomExtension());
$sanitizer = $builder->build([
    'extensions' => ['custom'],
    'tags'  => [
        'a' => ['allowed_attributes' => ['target']],
    ]
]);
$safeHtml = $sanitizer->sanitize($content);

@keywan-ghadami-oxid
Copy link

@zecka thank you, that example helped me to understand things. May I ask why you do not allow span tag in your application?

@zecka
Copy link
Author

zecka commented Oct 10, 2021

To be honest, I don't remember why I asked this question, but probably because I was trying to clean up some html content from an old wysiwyg that added spans with custom style tags.
Or maybe I was trying to clean up a "description" field from an rss feed to keep only the link tags.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants