MCPcopy Create free account
hub / github.com/socketstream/socketstream / decorate

Function decorate

docs/js/google-code-prettify.js:695–780  ·  view source on GitHub ↗
(job)

Source from the content-addressed store, hash-verified

693 * }</pre>
694 */
695 var decorate = function (job) {
696 var sourceCode = job.sourceCode, basePos = job.basePos;
697 /** Even entries are positions in source in ascending order. Odd enties
698 * are style markers (e.g., PR_COMMENT) that run from that position until
699 * the end.
700 * @type {Array.<number|string>}
701 */
702 var decorations = [basePos, PR_PLAIN];
703 var pos = 0; // index into sourceCode
704 var tokens = sourceCode.match(tokenizer) || [];
705 var styleCache = {};
706
707 for (var ti = 0, nTokens = tokens.length; ti < nTokens; ++ti) {
708 var token = tokens[ti];
709 var style = styleCache[token];
710 var match = void 0;
711
712 var isEmbedded;
713 if (typeof style === 'string') {
714 isEmbedded = false;
715 } else {
716 var patternParts = shortcuts[token.charAt(0)];
717 if (patternParts) {
718 match = token.match(patternParts[1]);
719 style = patternParts[0];
720 } else {
721 for (var i = 0; i < nPatterns; ++i) {
722 patternParts = fallthroughStylePatterns[i];
723 match = token.match(patternParts[1]);
724 if (match) {
725 style = patternParts[0];
726 break;
727 }
728 }
729
730 if (!match) { // make sure that we make progress
731 style = PR_PLAIN;
732 }
733 }
734
735 isEmbedded = style.length >= 5 && 'lang-' === style.substring(0, 5);
736 if (isEmbedded && !(match && typeof match[1] === 'string')) {
737 isEmbedded = false;
738 style = PR_SOURCE;
739 }
740
741 if (!isEmbedded) { styleCache[token] = style; }
742 }
743
744 var tokenStart = pos;
745 pos += token.length;
746
747 if (!isEmbedded) {
748 decorations.push(basePos + tokenStart, style);
749 } else { // Treat group 1 as an embedded block of source code.
750 var embeddedSource = match[1];
751 var embeddedSourceStart = token.indexOf(embeddedSource);
752 var embeddedSourceEnd = embeddedSourceStart + embeddedSource.length;

Callers

nothing calls this directly

Calls 2

appendDecorationsFunction · 0.85
langHandlerForExtensionFunction · 0.85

Tested by

no test coverage detected