use new-style tokens

This commit is contained in:
rolux 2012-05-27 21:33:04 +02:00
parent f98d997c4a
commit 2ea1283901

View file

@ -41,17 +41,18 @@ Ox.SourceViewer = function(options, self) {
Ox.get(self.options.file, function(source) { Ox.get(self.options.file, function(source) {
var sections = [{comment: '', code: ''}]; var sections = [{comment: '', code: ''}];
Ox.tokenize(source).forEach(function(token, i) { Ox.tokenize(source).forEach(function(token, i) {
var text = source.substr(token.offset, token.length), var type = token.type == 'comment' ? 'comment' : 'code';
type = token.type == 'comment' ? 'comment' : 'code'; if (!/^\/\//.test(token.value)) {
if (!/^\/\//.test(text)) {
if (type == 'comment') { if (type == 'comment') {
i && sections.push({comment: '', code: ''}); i && sections.push({comment: '', code: ''});
text = text.slice(2, -2); token.value = token.value.slice(2, -2);
self.options.replaceComment.forEach(function(replace) { self.options.replaceComment.forEach(function(replace) {
text = text.replace(replace[0], replace[1]); token.value = token.value.replace(
replace[0], replace[1]
);
}); });
} }
Ox.last(sections)[type] += text; Ox.last(sections)[type] += token.value;
} }
}); });
sections.forEach(function(section) { sections.forEach(function(section) {