I have a question about the Event Manager using an UDT.
Below a code snippet where I want to replace <pre> into <pre class="coding"><code>
Also all <br /> in the <pre> element has to be replaced into PHP_EOL
In a test file it works fine, but in cmsms the output is not as espected.
Please somebody can help me out here?
Template
Code: Select all
<!-- bootstrap -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.1/dist/css/bootstrap.min.css" crossorigin="anonymous">
<!-- highlight code frontend -->
<link href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.7.0/styles/googlecode.min.css" rel="stylesheet">
<__script__ src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.7.0/highlight.min.js"></__script>
<__script__>
document.addEventListener('DOMContentLoaded', function(e) {
document.querySelectorAll('pre > code').forEach(function(e) {
hljs.highlightBlock(e);
});
});
</__script>
Code: Select all
<p>HTML</p>
<pre><div id="demo"> <br /> <p class="blue">Een tekst</p><br /></div></pre>
<p>CSS</p>
<pre>#test {<br /> color: red;<br /> width: 80%;<br />}</pre>
<p>JavaScript</p>
<pre>window.addEventListener("load", function(event) {<br /> let total = 0;<br /> let items = document.querySelectorAll(".item)");<br /> for (let i=0; i < items.length; i++) {<br /> total = total + items[i].value;<br /> }<br />});</pre>
Code: Select all
$html = &$params['content'];
$regex = '/<pre>([\s\S.]*?)<\/pre>/';
$result = preg_replace_callback($regex, function ($matches) {
return '<pre class="coding"><code>' . str_replace('<br />', PHP_EOL, $matches[1]) . "</code></pre>";
}, $html);
return $result;
Code: Select all
UDT 'hightlight' added to Core -> ContentPreCompile