From ba4588f3fa317f93fbb3bc754d60a401f3004aea Mon Sep 17 00:00:00 2001 From: rolux Date: Sat, 26 May 2012 12:55:54 +0200 Subject: [PATCH] use new-style tokens --- source/Ox.UI/js/Code/Ox.SyntaxHighlighter.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/source/Ox.UI/js/Code/Ox.SyntaxHighlighter.js b/source/Ox.UI/js/Code/Ox.SyntaxHighlighter.js index 005a627b..b29e5f4b 100644 --- a/source/Ox.UI/js/Code/Ox.SyntaxHighlighter.js +++ b/source/Ox.UI/js/Code/Ox.SyntaxHighlighter.js @@ -58,12 +58,13 @@ Ox.SyntaxHighlighter = function(options, self) { tokens = Ox.tokenize(self.options.source); tokens.forEach(function(token, i) { var classNames, - substr = self.options.source.substr(token.offset, token.length); + type = token.type == 'identifier' + ? Ox.identify(token.value) : token.type; if ( - !(self.options.stripComments && token.type == 'comment') + !(self.options.stripComments && type == 'comment') ) { - classNames = 'Ox' + Ox.toTitleCase(token.type); - if (self.options.showWhitespace && token.type == 'whitespace') { + classNames = 'Ox' + Ox.toTitleCase(type); + if (self.options.showWhitespace && type == 'whitespace') { if (isAfterLinebreak() && hasIrregularSpaces()) { classNames += ' OxLeading'; } else if (isBeforeLinebreak()) { @@ -71,7 +72,7 @@ Ox.SyntaxHighlighter = function(options, self) { } } source += '' + - Ox.encodeHTML(substr) + Ox.encodeHTML(token.value) .replace(/ /g, whitespace) .replace(/\t/g, tab) .replace(/\n/g, linebreak) + ''; @@ -85,7 +86,7 @@ Ox.SyntaxHighlighter = function(options, self) { tokens[i + 1].type == 'linebreak'; } function hasIrregularSpaces() { - return substr.split('').reduce(function(prev, curr) { + return token.value.split('').reduce(function(prev, curr) { return prev + (curr == ' ' ? 1 : 0); }, 0) % self.options.tabSize; }