use new-style tokens
This commit is contained in:
parent
6c98a82800
commit
ba4588f3fa
1 changed files with 7 additions and 6 deletions
|
@ -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 += '<span class="' + classNames + '">' +
|
||||
Ox.encodeHTML(substr)
|
||||
Ox.encodeHTML(token.value)
|
||||
.replace(/ /g, whitespace)
|
||||
.replace(/\t/g, tab)
|
||||
.replace(/\n/g, linebreak) + '</span>';
|
||||
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue