Exercise/HTMLPurifierBundle

Custom config class

danaki opened this issue · 4 comments

I'm moving a project to Symfony4 from other framework where it defined like so:

<?php

namespace A\Namespace;

class HTMLPurifierConfig extends \HTMLPurifier_Config
{
    public static function create($config, $schema = null)
    {
        $ret = parent::create($config, $schema);

        $def = $ret->getHTMLDefinition(true);

        $def->info_tag_transform['div'] = new \HTMLPurifier_TagTransform_Simple('p');
        $def->info_tag_transform['h1'] = new \HTMLPurifier_TagTransform_Simple('h4');
        $def->info_tag_transform['h2'] = new \HTMLPurifier_TagTransform_Simple('h5');
        $def->info_tag_transform['h3'] = new \HTMLPurifier_TagTransform_Simple('h6');

...

Is it possible to introduce a config setting to override standard \HTMLPurifier_Config with a custom one from bundle config?

You should add your custom instance of purifier, see https://github.com/Exercise/HTMLPurifierBundle#purifiers-registry

Ok, how can I replace the default then? This:

    App\HtmlPurifier\DefaultHtmlPurifier:
        tags:
            - name: exercise.html_purifier
              profile: default

doesn't work

This:

services:
    App\HtmlPurifier\DefaultHtmlPurifier: '@exercise_html_purifier.default'

Also doesn't

Hello @danaki to override the default service and inject your purifier everywhere \HTMLPurifier is type hinted, you need to define it the other way around:

services:
    exercise_html_purifier.default: '@App\HtmlPurifier\DefaultHtmlPurifier'

I've updated the Readme in #68, so I'm going to close here. Feel free to reopen if it does not work as expected. Thanks!