Exercise / HTMLPurifierBundle

HTML Purifier is a standards-compliant HTML filter library written in PHP.
http://htmlpurifier.org/
Other
275 stars 56 forks source link

addElement to def #33

Closed lucasgranberg closed 9 years ago

lucasgranberg commented 9 years ago

I would like to add support for an element. I can do it like this in the controller:

        $config = $this->get('exercise_html_purifier.config.default');
        $def = $config->getHTMLDefinition(true);
        $section = $def->addElement(
            'section',
            'Block',  // content set
            'Flow', // allowed children
            'Common');
        $section->excludes = array('section' => true);

How can I do it systemwide?

spolischook commented 9 years ago

Looks like it's configuration resposobility

lucasgranberg commented 9 years ago

Did not find a way to do it via bundle config but I did however manage to add a configurator for the service like this: http://symfony.com/doc/current/components/dependency_injection/configurators.html

senaria commented 7 years ago

Hi @lucasgranberg I also need to add an element to the definition. How did you achieve this in the end? I took a look at the configurators, but this seems to only work if you define the service. However, this bundle is defining the services dynamically in the ExerciseHTMLPurifierExtension. I really need to be able to add a custom element, but cannot work out how to acheive it. Any help would be much appreciated.

lucasgranberg commented 7 years ago

I don't remember and I don't have access to the code anymore. The link is dead. I think this is the right one: http://symfony.com/doc/current/service_container/configurators.html

However I think you can add elements directly trough symfony config.

exercise_html_purifier:
    onlylinksandparagraphs:
        HTML.Allowed: 'a[href],p'

http://htmlpurifier.org/live/configdoc/plain.html#HTML.Allowed

senaria commented 7 years ago

Thank for your reply @lucasgranberg

I am trying to add an element that does not exist (e.g My Content). HTML.Allowed apparently only allows you to add already defined elements. Also it seems to override all allowed elements.

Any ideas? I would be very grateful 😄

zxzzxxzx commented 6 years ago

Hello, did you manage to fix the issue? Just ran into the sams issue too.