<commit_before><?php

namespace Etu\Core\CoreBundle\Twig\Extension;

use Symfony\Component\DependencyInjection\ContainerInterface;

class HTMLPurifierExtension extends \Twig_Extension
{
    private $container;

    private $purifiers = array();

    /**
     * Constructor.
     *
     * @param \HTMLPurifier $purifier
     */
    public function __construct(ContainerInterface $container)
    {
        $this->container = $container;
    }

    /**
     * @see Twig_Extension::getFilters()
     */
    public function getFilters()
    {
        return array(
            new \Twig_SimpleFilter('purify', [$this, 'purify'], ['is_safe' => ['html']]),
        );
    }

    /**
     * Filter the input through an HTMLPurifier service.
     *
     * @param string $string
     * @param string $profile
     *
     * @return string
     */
    public function purify($string, $profile = 'default')
    {
        if ($profile == 'email') {
            $config = \HTMLPurifier_Config::createDefault();
            $config->set('HTML.Doctype', 'HTML 4.01 Transitional');
            $config->set('Cache.SerializerPath', '/tmp');
            // set from param:
            $config->set('HTML.Allowed', 'h3,h4,h5,h6,b,i,strong,em,p[style|align],li,ul,ol,img[src|alt],a[href|title|target|rel]');
            $config->set('CSS.AllowedProperties', 'width,height,text-align,padding-left,max-width,max-height');
            $config->set('Attr.AllowedClasses', '');
        }
        // default profile
        else {
            // Load HTML5 purifier config
            $config = load_htmlpurifier([
                'HTML.Allowed' => 'h2[id],h3[id],h4[id],h5[id],h6[id],pre[class],code,div[class],strong,em,p[style],li,ul,ol,img[src|alt],a[href|title|target|rel],video[controls|width|height],source[src|type],table[class|style],tbody,tr,td,iframe[src|width|height|allowfullscreen]',
                'CSS.AllowedProperties' => 'width,height,text-align,padding-left,max-width,max-height',
                'Attr.AllowedClasses' => 'alert,alert-error,alert-warning,alert-info,alert-success,pull-left,pull-right,mce-toc,table,table-bordered,'
                    .'language-auto,language-nohighlight,language-1c,language-abnf,language-accesslog,language-ada,language-armasm,language-avrasm,language-actionscript,language-apache,language-applescript,language-asciidoc,language-aspectj,language-autohotkey,language-autoit,language-awk,language-axapta,language-bash,language-basic,language-bnf,language-brainfuck,language-cs,language-cpp,language-cal,language-cos,language-cmake,language-coq,language-csp,language-css,language-capnproto,language-clojure,language-coffeescript,language-crmsh,language-crystal,language-d,language-dns,language-dos,language-dart,language-delphi,language-lazarus,language-diff,language-django,language-dockerfile,language-dsconfig,language-dts,language-dust,language-ebnf,language-elixir,language-elm,language-erlang,language-excel,language-fsharp,language-fix,language-fortran,language-gcode,language-gams,language-gauss,language-gherkin,language-go,language-golo,language-gradle,language-groovy,language-xml,language-http,language-haml,language-handlebars,language-haskell,language-haxe,language-ini,language-inform7,language-irpf90,language-json,language-java,language-javascript,language-lasso,language-less,language-ldif,language-lisp,language-livecodeserver,language-livescript,language-lua,language-makefile,language-markdown,language-mathematica,language-matlab,language-maxima,language-mel,language-mercury,language-mizar,language-mojolicious,language-monkey,language-moonscript,language-nsis,language-nginx,language-nimrod,language-nix,language-ocaml,language-objectivec,language-glsl,language-openscad,language-ruleslanguage,language-oxygene,language-pf,language-php,language-parser3,language-perl,language-pony,language-powershell,language-processing,language-prolog,language-protobuf,language-puppet,language-python,language-profile,language-k,language-qml,language-r,language-rib,language-rsl,language-graph,language-ruby,language-rust,language-scss,language-sql,language-p21,language-scala,language-scheme,language-scilab,language-smali,language-smalltalk,language-stan,language-stata,language-stylus,language-subunit,language-swift,language-tap,language-tcl,language-tex,language-thrift,language-tp,language-twig,language-typescript,language-vbnet,language-vbscript,language-vhdl,language-vala,language-verilog,language-vim,language-x86asm,language-xl,language-xpath,language-zephir',
                'Attr.EnableID' => true,
                'Attr.IDBlacklistRegexp' => '/^(?!mcetoc_)/'
            ]);
        }<commit_msg>Allow image center alignement in editor<commit_after><?php

namespace Etu\Core\CoreBundle\Twig\Extension;

use Symfony\Component\DependencyInjection\ContainerInterface;

class HTMLPurifierExtension extends \Twig_Extension
{
    private $container;

    private $purifiers = array();

    /**
     * Constructor.
     *
     * @param \HTMLPurifier $purifier
     */
    public function __construct(ContainerInterface $container)
    {
        $this->container = $container;
    }

    /**
     * @see Twig_Extension::getFilters()
     */
    public function getFilters()
    {
        return array(
            new \Twig_SimpleFilter('purify', [$this, 'purify'], ['is_safe' => ['html']]),
        );
    }

    /**
     * Filter the input through an HTMLPurifier service.
     *
     * @param string $string
     * @param string $profile
     *
     * @return string
     */
    public function purify($string, $profile = 'default')
    {
        if ($profile == 'email') {
            $config = \HTMLPurifier_Config::createDefault();
            $config->set('HTML.Doctype', 'HTML 4.01 Transitional');
            $config->set('Cache.SerializerPath', '/tmp');
            // set from param:
            $config->set('HTML.Allowed', 'h3,h4,h5,h6,b,i,strong,em,p[style|align],li,ul,ol,img[src|alt|style|height|width],a[href|title|target|rel]');
            $config->set('CSS.AllowedProperties', 'width,height,text-align,padding-left,max-width,max-height');
            $config->set('Attr.AllowedClasses', '');
        }
        // default profile
        else {
            // Load HTML5 purifier config
            $config = load_htmlpurifier([
                'HTML.Allowed' => 'h2[id],h3[id],h4[id],h5[id],h6[id],pre[class],code,div[class|style],strong,em,p[style],li,ul,ol,img[src|alt|style|height|width],a[href|title|target|rel],video[controls|width|height],source[src|type],table[class|style],tbody,tr,td,iframe[src|width|height|allowfullscreen]',
                'CSS.AllowTricky' => true,
                'CSS.AllowedProperties' => 'width,height,text-align,padding-left,max-width,max-height,margin-left,margin-right,display',
                'Attr.AllowedClasses' => 'alert,alert-error,alert-warning,alert-info,alert-success,pull-left,pull-right,mce-toc,table,table-bordered,'
                    .'language-auto,language-nohighlight,language-1c,language-abnf,language-accesslog,language-ada,language-armasm,language-avrasm,language-actionscript,language-apache,language-applescript,language-asciidoc,language-aspectj,language-autohotkey,language-autoit,language-awk,language-axapta,language-bash,language-basic,language-bnf,language-brainfuck,language-cs,language-cpp,language-cal,language-cos,language-cmake,language-coq,language-csp,language-css,language-capnproto,language-clojure,language-coffeescript,language-crmsh,language-crystal,language-d,language-dns,language-dos,language-dart,language-delphi,language-lazarus,language-diff,language-django,language-dockerfile,language-dsconfig,language-dts,language-dust,language-ebnf,language-elixir,language-elm,language-erlang,language-excel,language-fsharp,language-fix,language-fortran,language-gcode,language-gams,language-gauss,language-gherkin,language-go,language-golo,language-gradle,language-groovy,language-xml,language-http,language-haml,language-handlebars,language-haskell,language-haxe,language-ini,language-inform7,language-irpf90,language-json,language-java,language-javascript,language-lasso,language-less,language-ldif,language-lisp,language-livecodeserver,language-livescript,language-lua,language-makefile,language-markdown,language-mathematica,language-matlab,language-maxima,language-mel,language-mercury,language-mizar,language-mojolicious,language-monkey,language-moonscript,language-nsis,language-nginx,language-nimrod,language-nix,language-ocaml,language-objectivec,language-glsl,language-openscad,language-ruleslanguage,language-oxygene,language-pf,language-php,language-parser3,language-perl,language-pony,language-powershell,language-processing,language-prolog,language-protobuf,language-puppet,language-python,language-profile,language-k,language-qml,language-r,language-rib,language-rsl,language-graph,language-ruby,language-rust,language-scss,language-sql,language-p21,language-scala,language-scheme,language-scilab,language-smali,language-smalltalk,language-stan,language-stata,language-stylus,language-subunit,language-swift,language-tap,language-tcl,language-tex,language-thrift,language-tp,language-twig,language-typescript,language-vbnet,language-vbscript,language-vhdl,language-vala,language-verilog,language-vim,language-x86asm,language-xl,language-xpath,language-zephir',
                'Attr.EnableID' => true,
                'Attr.IDBlacklistRegexp' => '/^(?!mcetoc_)/'
            ]);
        }
{'fraction_non_alphanumeric': 0.14594365600508366, 'fraction_numerical': 0.004660029654734167, 'mean_word_length': 4.9993646759847525, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 28, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1372270', 'n_tokens_mistral': 3016, 'n_tokens_neox': 2944, 'n_words': 199}