-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbasic.php
38 lines (29 loc) · 1005 Bytes
/
basic.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
<?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-/");
$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
</article>
</section>
</div>
HTML;
$purifier = new HTMLPurifierX($config);
$html = $purifier->purify($html);
echo $html;