-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhtml5.php
43 lines (32 loc) · 1.2 KB
/
html5.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php
ini_set("display_errors", 1);
require_once __DIR__ . "/../vendor/autoload.php";
$config = HTMLPurifierX_Config::createDefault();
$config->set('Cache.SerializerPath', sys_get_temp_dir());
$config->set('Cache.DefinitionImpl', null);
$config->set('AutoFormat.RemoveEmpty', false);
// custom config
$config->set('HTML.AllowDataAttributes', true);
$config->set('HTML.AllowNamespacedAttributes', true);
$config->set('HTML.AllowCustomElements', true);
$config->set('HTML.AllowCustomElementsRegex', "/^x-/");
$config->set('HTML.DefinitionID', "HTML5_TEST");
$config = HTMLPurifier_HTML5Config::inherit($config);
$html = <<<HTML
<div class="custom-components" data-ref="myDiv">
<x-panel data-ref="customPanel">
<x-body data-ref="customPanelBody">
<x-button class="custom-btn" data-value="1" on:click="alert('...')">Custom Button</x-button>
</x-body>
</x-panel>
<section>
<article data-id="12345">
test article
<x-button class="custom-btn" data-value="1" on:click="alert('...')">Custom Button Inside HTML5 Node</x-button>
</article>
</section>
</div>
HTML;
$purifier = new HTMLPurifierX($config);
$html = $purifier->purify($html);
echo $html;