highlightjs and orgmode

Source code in org files is exported to html in a pre tag like this

<pre class="src src-javascript"> … </pre>

The function hljs.highlightOnLoad() provided by highlightjs does not work with this structure. A custom function must be used:

var hlf = function() {
    Array.prototype.forEach.call(document.querySelectorAll('pre.src'), function(block) {
        var css,lang;
        css = block.getAttribute('class');
        lang = css.replace(/src-?| /g, '');
        if (lang == 'js') {
            lang = 'javascript';
        }
        block.setAttribute('class', css + ' ' + lang);
        hljs.highlightBlock(block);});
};
addEventListener('DOMContentLoaded', hlf);
addEventListener('load', hlf);

Date: 2015-05-25

Created: 2015-12-08 Di 23:21

Validate