website-htmx-rustelo-code/site/public/js/highlight-utils.min.js
2026-07-10 03:44:13 +01:00

1 line
No EOL
980 B
JavaScript

window.highlightCode=function(){document.querySelectorAll('pre code:not(.hljs)').forEach(function(block){if(typeof hljs!=='undefined'&&hljs.highlightElement){hljs.highlightElement(block);}});};window.highlightContainer=function(containerSelector){const container=document.querySelector(containerSelector);if(container&&typeof hljs!=='undefined'){container.querySelectorAll('pre code:not(.hljs)').forEach(function(block){hljs.highlightElement(block);});}};document.addEventListener('DOMContentLoaded',function(){const observer=new MutationObserver(function(mutations){let shouldHighlight=false;mutations.forEach(function(mutation){if(mutation.type==='childList'&&mutation.addedNodes.length>0){mutation.addedNodes.forEach(function(node){if(node.nodeType===1&&(node.tagName==='PRE'||node.querySelector('pre'))){shouldHighlight=true;}});}});if(shouldHighlight){setTimeout(function(){window.highlightCode();},100);}});observer.observe(document.body,{childList: true,subtree: true});});