src/rainbow.js
function _highlight(node, callback) {
    callback = callback || function() {};

    // The first argument can be an Event or a DOM Element.
    //
    // I was originally checking instanceof Event but that made it break
    // when using mootools.
    //
    // @see https://github.com/ccampbell/rainbow/issues/32
    node = node && typeof node.getElementsByTagName === 'function' ? node : document;

    const preBlocks = node.getElementsByTagName('pre');
    const codeBlocks = node.getElementsByTagName('code');
    const finalPreBlocks = [];
    const finalCodeBlocks = [];

    // First loop through all pre blocks to find which ones to highlight
    for (const preBlock of preBlocks) {
        _addPreloader(preBlock);

        // Strip whitespace around code tags when they are inside of a pre
        // tag.  This makes the themes look better because you can't
        // accidentally add extra linebreaks at the start and end.
        //
        // When the pre tag contains a code tag then strip any extra
        // whitespace.
        //
        // For example:
        //
        // <pre>
        //      <code>var foo = true;</code>
        // </pre>
        //
        // will become:
        //
        // <pre><code>var foo = true;</code></pre>
        //
        // If you want to preserve whitespace you can use a pre tag on
        // its own without a code tag inside of it.
        if (preBlock.getElementsByTagName('code').length) {

            // This fixes a race condition when Rainbow.color is called before
            // the previous color call has finished.
            if (!preBlock.getAttribute('data-trimmed')) {
                preBlock.setAttribute('data-trimmed', true);
                preBlock.innerHTML = preBlock.innerHTML.trim();
            }
            continue;
        }

        // If the pre block has no code blocks then we are going to want to
        // process it directly.
        finalPreBlocks.push(preBlock);
    }

    // @see http://stackoverflow.com/questions/2735067/how-to-convert-a-dom-node-list-to-an-array-in-javascript
    // We are going to process all <code> blocks
    for (const codeBlock of codeBlocks) {
        finalCodeBlocks.push(codeBlock);
    }

    _highlightCodeBlocks(finalCodeBlocks.concat(finalPreBlocks), callback);
}
function _highlight(node, callback) {
    callback = callback || function() {};

    // The first argument can be an Event or a DOM Element.
    //
    // I was originally checking instanceof Event but that made it break
    // when using mootools.
    //
    // @see https://github.com/ccampbell/rainbow/issues/32
    node = node && typeof node.getElementsByTagName === 'function' ? node : document;

    const preBlocks = node.getElementsByTagName('pre');
    const codeBlocks = node.getElementsByTagName('code');
    const finalPreBlocks = [];
    const finalCodeBlocks = [];

    // First loop through all pre blocks to find which ones to highlight
    for (const preBlock of preBlocks) {
        _addPreloader(preBlock);

        // Strip whitespace around code tags when they are inside of a pre
        // tag.  This makes the themes look better because you can't
        // accidentally add extra linebreaks at the start and end.
        //
        // When the pre tag contains a code tag then strip any extra
        // whitespace.
        //
        // For example:
        //
        // <pre>
        //      <code>var foo = true;</code>
        // </pre>
        //
        // will become:
        //
        // <pre><code>var foo = true;</code></pre>
        //
        // If you want to preserve whitespace you can use a pre tag on
        // its own without a code tag inside of it.
        if (preBlock.getElementsByTagName('code').length) {

            // This fixes a race condition when Rainbow.color is called before
            // the previous color call has finished.
            if (!preBlock.getAttribute('data-trimmed')) {
                preBlock.setAttribute('data-trimmed', true);
                preBlock.innerHTML = preBlock.innerHTML.trim();
            }
            continue;
        }

        // If the pre block has no code blocks then we are going to want to
        // process it directly.
        finalPreBlocks.push(preBlock);
    }

    // @see http://stackoverflow.com/questions/2735067/how-to-convert-a-dom-node-list-to-an-array-in-javascript
    // We are going to process all <code> blocks
    for (const codeBlock of codeBlocks) {
        finalCodeBlocks.push(codeBlock);
    }

    _highlightCodeBlocks(finalCodeBlocks.concat(finalPreBlocks), callback);
}
function _highlight ( node , callback ) { callback = callback || function ( ) { } ; // The first argument can be an Event or a DOM Element. // // I was originally checking instanceof Event but that made it break // when using mootools. // // @see https://github.com/ccampbell/rainbow/issues/32 node = node && typeof node . getElementsByTagName === 'function' ? node : document ; const preBlocks = node . getElementsByTagName ( 'pre' ) ; const codeBlocks = node . getElementsByTagName ( 'code' ) ; const finalPreBlocks = [ ] ; const finalCodeBlocks = [ ] ; // First loop through all pre blocks to find which ones to highlight for ( const preBlock of preBlocks ) { _addPreloader ( preBlock ) ; // Strip whitespace around code tags when they are inside of a pre // tag.  This makes the themes look better because you can't // accidentally add extra linebreaks at the start and end. // // When the pre tag contains a code tag then strip any extra // whitespace. // // For example: // // <pre> //      <code>var foo = true;</code> // </pre> // // will become: // // <pre><code>var foo = true;</code></pre> // // If you want to preserve whitespace you can use a pre tag on // its own without a code tag inside of it. if ( preBlock . getElementsByTagName ( 'code' ) . length ) { // This fixes a race condition when Rainbow.color is called before // the previous color call has finished. if ( ! preBlock . getAttribute ( 'data-trimmed' ) ) { preBlock . setAttribute ( 'data-trimmed' , true ) ; preBlock . innerHTML = preBlock . innerHTML . trim ( ) ; } continue ; } // If the pre block has no code blocks then we are going to want to // process it directly. finalPreBlocks . push ( preBlock ) ; } // @see http://stackoverflow.com/questions/2735067/how-to-convert-a-dom-node-list-to-an-array-in-javascript // We are going to process all <code> blocks for ( const codeBlock of codeBlocks ) { finalCodeBlocks . push ( codeBlock ) ; } _highlightCodeBlocks ( finalCodeBlocks . concat ( finalPreBlocks ) , callback ) ; }
Browser Only - Start highlighting all the code blocks

@param {Element} node       HTMLElement to search within
@param {Function} callback
@return {void}
Browser Only - Start highlighting all the code blocks