Search by

prestashopheaven / runtime-rich-text

georgevanengers

Turns HTML from a rich text editor (TinyMCE, a webservice) into a whitelisted node tree that a template renders with every text escaped, so no merchant HTML reaches the page as it is and no nofilter is needed; and into plain text (JSON-LD, previews).

Package info

github.com/prestashopheaven/runtime-rich-text

pkg:composer/prestashopheaven/runtime-rich-text

Statistics

Installs: 40

Dependents: 0

Suggesters: 0

Stars: 0

v1.1.0 2026-12-02 02:41 UTC

This package is auto-updated.

Last update: 2026-12-02 02:57:31 UTC


README

Turns HTML from a rich text editor (TinyMCE, a webservice) into a whitelisted node tree that a template renders with every text escaped, so no merchant HTML reaches the page as it is and no nofilter is needed; and into plain text (JSON-LD, previews).

Use when

A module shows HTML that a merchant or an API client wrote (an answer, a description) in the front office or in structured data, and must pass the online validator, which refuses nofilter.

Install

composer require prestashopheaven/runtime-rich-text

Usage

In a presenter (pure PHP, unit-testable):

use PrestaShopHeaven\Runtime\RichText\RichTextNodes;

$richText = new RichTextNodes();
$nodes = $richText->fromHtml($answerHtml);   // list of ['type' => 'text', 'text' => ...] / ['type' => 'element', 'tag' => ..., 'children' => [...]]
$plain = $richText->plainText($nodes);       // text with blank lines between blocks, for JSON-LD or a preview

Kept: p (div becomes p), br, strong/b, em/i, u, s, ul, ol, li, h1-h3 as h3, h4-h6 as h4, blockquote and a (only an http(s) URL, a path of the shop or a fragment; external is true for http(s)). Everything else is unwrapped, every attribute is dropped. Nesting deeper than RichTextNodes::MAX_DEPTH becomes text.

The module renders the tree with a recursive Smarty function in its own partial (every text through |escape:'html':'UTF-8', every tag written literally), so no nofilter is needed; see views/templates/front/_partials/description.tpl of heaveneventcalendar or views/templates/hook/_partials/answer.tpl of heavenproductfaq.

Read-only split of prestashopheaven/mono-runtime-communication: changes, issues and pull requests go there. MIT License.