AcidLava Posted October 29 Share Posted October 29 (edited) 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 October 29 by AcidLava (see edit history) Link to comment Share on other sites More sharing options...
ecomsoft Posted October 29 Share Posted October 29 (edited) are you talking about the product descriptions or somewhere else Edited October 29 by ecomsoft (see edit history) Link to comment Share on other sites More sharing options...
AcidLava Posted October 29 Author Share Posted October 29 @ecomsoft everywhere the native html editor is involved (product descriptions included) Link to comment Share on other sites More sharing options...
alex_developer Posted October 29 Share Posted October 29 3 hours ago, AcidLava said: What's the cleanest solution to work around this issue? As an option, add an attribute to the HTML Purifier configuration PrestaShop allows you to extend the list of allowed attributes in HTMLPurifier_Config. This is done by overriding TinyMCE / CMS Controller, for example in a module or override. Link to comment Share on other sites More sharing options...
AcidLava Posted October 29 Author Share Posted October 29 (edited) 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 October 29 by AcidLava (see edit history) Link to comment Share on other sites More sharing options...
alex_developer Posted October 29 Share Posted October 29 (edited) 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’]); Edited October 29 by Oleksandr (see edit history) Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now