var decorate = function()

in content/resources/js/prettify.js [678:763]


        var decorate = function (job) {
            var sourceCode = job.sourceCode, basePos = job.basePos;
            /** Even entries are positions in source in ascending order.  Odd enties
             * are style markers (e.g., PR_COMMENT) that run from that position until
             * the end.
             * @type {Array.<number|string>}
             */
            var decorations = [basePos, PR_PLAIN];
            var pos = 0;  // index into sourceCode
            var tokens = sourceCode.match(tokenizer) || [];
            var styleCache = {};

            for (var ti = 0, nTokens = tokens.length; ti < nTokens; ++ti) {
                var token = tokens[ti];
                var style = styleCache[token];
                var match = void 0;

                var isEmbedded;
                if (typeof style === 'string') {
                    isEmbedded = false;
                } else {
                    var patternParts = shortcuts[token.charAt(0)];
                    if (patternParts) {
                        match = token.match(patternParts[1]);
                        style = patternParts[0];
                    } else {
                        for (var i = 0; i < nPatterns; ++i) {
                            patternParts = fallthroughStylePatterns[i];
                            match = token.match(patternParts[1]);
                            if (match) {
                                style = patternParts[0];
                                break;
                            }
                        }

                        if (!match) {  // make sure that we make progress
                            style = PR_PLAIN;
                        }
                    }

                    isEmbedded = style.length >= 5 && 'lang-' === style.substring(0, 5);
                    if (isEmbedded && !(match && typeof match[1] === 'string')) {
                        isEmbedded = false;
                        style = PR_SOURCE;
                    }

                    if (!isEmbedded) { styleCache[token] = style; }
                }

                var tokenStart = pos;
                pos += token.length;

                if (!isEmbedded) {
                    decorations.push(basePos + tokenStart, style);
                } else {  // Treat group 1 as an embedded block of source code.
                    var embeddedSource = match[1];
                    var embeddedSourceStart = token.indexOf(embeddedSource);
                    var embeddedSourceEnd = embeddedSourceStart + embeddedSource.length;
                    if (match[2]) {
                        // If embeddedSource can be blank, then it would match at the
                        // beginning which would cause us to infinitely recurse on the
                        // entire token, so we catch the right context in match[2].
                        embeddedSourceEnd = token.length - match[2].length;
                        embeddedSourceStart = embeddedSourceEnd - embeddedSource.length;
                    }
                    var lang = style.substring(5);
                    // Decorate the left of the embedded source
                    appendDecorations(
                        basePos + tokenStart,
                        token.substring(0, embeddedSourceStart),
                        decorate, decorations);
                    // Decorate the embedded source
                    appendDecorations(
                        basePos + tokenStart + embeddedSourceStart,
                        embeddedSource,
                        langHandlerForExtension(lang, embeddedSource),
                        decorations);
                    // Decorate the right of the embedded section
                    appendDecorations(
                        basePos + tokenStart + embeddedSourceEnd,
                        token.substring(embeddedSourceEnd),
                        decorate, decorations);
                }
            }
            job.decorations = decorations;
        };