forked from 0x2620/oxjs
prototype of a documentation page
This commit is contained in:
parent
a6ed310087
commit
b1d171282c
8 changed files with 476 additions and 85 deletions
|
|
@ -39,7 +39,8 @@ Ox.SyntaxHighlighter = function(options, self) {
|
|||
self.source = '';
|
||||
self.tokens = Ox.tokenize(self.options.source);
|
||||
self.tokens.forEach(function(token, i) {
|
||||
var classNames;
|
||||
var classNames,
|
||||
source = self.options.source.substr(token.offset, token.length);
|
||||
if (
|
||||
!(self.options.stripComments && token.type == 'comment')
|
||||
) {
|
||||
|
|
@ -52,7 +53,7 @@ Ox.SyntaxHighlighter = function(options, self) {
|
|||
}
|
||||
}
|
||||
self.source += '<span class="' + classNames + '">' +
|
||||
encodeToken(token.source, token.type) + '</span>';
|
||||
encodeToken(source, token.type) + '</span>';
|
||||
}
|
||||
self.cursor += token.length;
|
||||
function isAfterLinebreak() {
|
||||
|
|
@ -64,7 +65,7 @@ Ox.SyntaxHighlighter = function(options, self) {
|
|||
self.tokens[i + 1].type == 'linebreak';
|
||||
}
|
||||
function hasIrregularSpaces() {
|
||||
return token.source.split('').reduce(function(prev, curr) {
|
||||
return source.split('').reduce(function(prev, curr) {
|
||||
return prev + (curr == ' ' ? 1 : 0);
|
||||
}, 0) % self.options.tabLength;
|
||||
}
|
||||
|
|
@ -107,11 +108,11 @@ Ox.SyntaxHighlighter = function(options, self) {
|
|||
.html(self.source)
|
||||
.appendTo(that);
|
||||
|
||||
function encodeToken(source, type) {
|
||||
function encodeToken(source, token) {
|
||||
var linebreak = '<br/>',
|
||||
tab = Ox.repeat(' ', self.options.tabLength);
|
||||
if (self.options.showLinebreaks) {
|
||||
if (type == 'linebreak') {
|
||||
if (token.type == 'linebreak') {
|
||||
linebreak = '\u21A9' + linebreak;
|
||||
} else {
|
||||
linebreak = '<span class="OxLinebreak">\u21A9</span>' + linebreak;
|
||||
|
|
@ -120,11 +121,10 @@ Ox.SyntaxHighlighter = function(options, self) {
|
|||
if (self.options.showTabs) {
|
||||
tab = '<span class="OxTab">\u2192' + tab.substr(6) + '</span>';
|
||||
}
|
||||
source = Ox.encodeHTML(source)
|
||||
return Ox.encodeHTML(source)
|
||||
.replace(/ /g, ' ')
|
||||
.replace(/\t/g, tab)
|
||||
.replace(/\n/g, linebreak);
|
||||
return source;
|
||||
}
|
||||
|
||||
self.setOption = function() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue