cradeq/commonmark-html-whitelist-extension

Allows HTML tags to be used in Markdown, while still escaping or stripping all other HTML input.

v1.0.1 2025-06-05 12:55 UTC

This package is auto-updated.

Last update: 2025-06-05 12:56:21 UTC


README

This package allows any HTML tags to be used in Markdown, while still escaping or stripping all other HTML input. Only tags without attributes or styling are supported. Content of the HTML elements remains intact.

Install

This project can be installed via composer:

composer require cradeq/commonmark-html-whitelist-extension

Usage

use Cradeq\CommonMark\HtmlWhitelistExtension;
use League\CommonMark\Environment\Environment;
use League\CommonMark\Extension\CommonMark\CommonMarkCoreExtension;

$environment = new Environment([
    'html_input' => 'strip', // Both strip and escape are supported
    'html_whitelist' => [
        'tags' => ['br', 'sub'], // Any set of html tags
    ],
]);
$environment->addExtension(new CommonMarkCoreExtension);
$environment->addExtension(new HtmlWhitelistExtension);