Jump to content

HTML purifier


AcidLava

Recommended Posts

Hello,

On Prestashop 8.2.3, when I add something like loading="lazy" in the source code of an element via the text editor, it disappears as soon as I save (because of HTML Purifier?)? This is quite problematic, since even when writing a blog post, the code gets completely altered at the slightest mistake.

What's the cleanest solution to work around this issue?

Thank you.

Edited by AcidLava (see edit history)
Link to comment
Share on other sites

I tried this via Tools.php but it doesn't work.

 

<?php

class ToolsOverride extends Tools
{
    public static function purify($html, $uri_unescape = false)
    {
        static $purifier = null;
        if (!$purifier) {
            require_once _PS_TOOL_DIR_.'htmlpurifier/HTMLPurifier.standalone.php';
            $config = HTMLPurifier_Config::createDefault();

            // Ajout de l’attribut "loading" pour les balises <img>
            $def = $config->getHTMLDefinition(true);
            if ($def) {
                $def->addAttribute('img', 'loading', 'Enum#lazy,eager,auto');
            }

            $purifier = new HTMLPurifier($config);
        }

        return $purifier->purify($html);
    }
}



 

Edited by AcidLava (see edit history)
Link to comment
Share on other sites

3 hours ago, AcidLava said:

I tried this via Tools.php but it doesn't work.

Ovveridethe purifyHTML method in Tools.

Add attributes to an existing tag:

$def->addAttribute(‘a’, ‘data-locale’, ‘Text’);

 

Add a new tag:

$def->addElement(‘canvas’, ‘Block’, ‘Flow’, ‘Common’, [‘data-url’ => ‘URI’]);

 

image_2025-10-29_18-36-26.png

Edited by Oleksandr (see edit history)
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...