summaryrefslogtreecommitdiff
path: root/javascript/videojs/docs/legacy-docs/api/js/highlight-syntax.js
blob: 2fc93704fd15305516d2e216a4da14cbad964b0d (plain)
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
BCLSHighlighter = (function(hljs) {
    var codeBlocks = document.querySelectorAll('pre>code'),
        i,
        iMax,
        txt,
        reLT = new RegExp('<', 'g'),
        reGT = new RegExp('>;', 'g');

    /**
     * tests for all the ways a variable might be undefined or not have a value
     * @param {*} x the variable to test
     * @return {Boolean} true if variable is defined and has a value
     */
    function isDefined(x) {
        if (x === '' || x === null || x === undefined || x === NaN) {
            return false;
        }
        return true;
    };

    if (isDefined(codeBlocks)) {
        iMax = codeBlocks.length;
        for (i = 0; i < iMax; i++) {
            txt = codeBlocks[i].innerHTML.toString();
            txt = txt.replace(reLT, '&lt;');
            txt = txt.replace(reGT, '&gt;');
            codeBlocks[i].innerHTML = txt;
            hljs.highlightBlock(codeBlocks[i]);
        }
    }
})(hljs);