Last active
November 17, 2018 01:45
-
-
Save yookoala/a10caeb62f0576ce926f76acd8b7e517 to your computer and use it in GitHub Desktop.
HTMLPurifier add support to details and summary
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "yookoala/htmlpurifier-example", | |
"authors": [ | |
{ | |
"name": "Koala Yeung", | |
"email": "koalay at gmail dot com" | |
} | |
], | |
"require": { | |
"ezyang/htmlpurifier": "^4.10" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once __DIR__ . '/vendor/autoload.php'; | |
ob_start(); | |
?> | |
<html> | |
<head> | |
<title>HTMLPurifier test</title> | |
</head> | |
<body> | |
<div> | |
<p>Hello world</p> | |
</div> | |
<details open="true"> | |
<summary>Hello content</summary> | |
<div> | |
<p>Something new</p> | |
</div> | |
</details> | |
</body> | |
</html> | |
<?php | |
$contents = ob_get_clean(); | |
$config = HTMLPurifier_Config::createDefault(); | |
$config->set('HTML.Allowed', 'div,p,ul[style],ol,li,details[open],summary'); | |
$def = $config->getHTMLDefinition(true); | |
$def->addElement('details', 'Block', 'Flow', 'Common', [ | |
'open' => 'Bool#open', | |
]); | |
$def->addElement('summary', 'Inline', 'Inline', 'Common'); | |
$purifier = new HTMLPurifier($config); | |
echo $purifier->purify($contents); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment