cradeq/commonmark-html-whitelist-extension

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

Maintainers

Package info

github.com/Cradeq/commonmark-html-whitelist-extension

Type:commonmark-extension

pkg:composer/cradeq/commonmark-html-whitelist-extension

Statistics

Installs: 6 342

Dependents: 0

Suggesters: 0

Stars: 2

Open Issues: 0

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

This package is auto-updated.

Last update: 2026-03-05 14:32:47 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);