improve performance of DocPanel by returning tokens (not source) from Ox.doc and making Ox.SyntaxHighlighter accept tokens
This commit is contained in:
parent
6b12776ed9
commit
d9c69a0975
2 changed files with 10 additions and 9 deletions
|
@ -13,7 +13,7 @@ Ox.SyntaxHighlighter <f:Ox.Element> Syntax Highlighter
|
||||||
showLineNumbers <b|false> If true, show line numbers
|
showLineNumbers <b|false> If true, show line numbers
|
||||||
showWhitespace <b|false> If true, show whitespace
|
showWhitespace <b|false> If true, show whitespace
|
||||||
showTabs <b|false> If true, show tabs
|
showTabs <b|false> If true, show tabs
|
||||||
source <s|''> JavaScript source
|
source <s|[o]|''> JavaScript source, or array of tokens
|
||||||
stripComments <b|false> If true, strip comments
|
stripComments <b|false> If true, strip comments
|
||||||
tabSize <n|4> Number of spaces per tab
|
tabSize <n|4> Number of spaces per tab
|
||||||
self <o> Shared private variable
|
self <o> Shared private variable
|
||||||
|
@ -52,10 +52,9 @@ Ox.SyntaxHighlighter = function(options, self) {
|
||||||
'<span class="OxTab">\u2192</span>' : ''
|
'<span class="OxTab">\u2192</span>' : ''
|
||||||
) + Ox.repeat(' ', self.options.tabSize - self.options.showTabs),
|
) + Ox.repeat(' ', self.options.tabSize - self.options.showTabs),
|
||||||
whitespace = self.options.showWhitespace ? '\u00B7' : ' ';
|
whitespace = self.options.showWhitespace ? '\u00B7' : ' ';
|
||||||
self.options.source = self.options.source
|
tokens = Ox.isArray(self.options.source)
|
||||||
.replace(/\r\n/g, '\n')
|
? self.options.source
|
||||||
.replace(/\r/g, '\n');
|
: Ox.tokenize(self.options.source);
|
||||||
tokens = Ox.tokenize(self.options.source);
|
|
||||||
tokens.forEach(function(token, i) {
|
tokens.forEach(function(token, i) {
|
||||||
var classNames,
|
var classNames,
|
||||||
type = token.type == 'identifier'
|
type = token.type == 'identifier'
|
||||||
|
|
|
@ -18,7 +18,11 @@ Ox.doc <f> Generates documentation for annotated JavaScript
|
||||||
<code>"event"</code>, <code>"function"</code>
|
<code>"event"</code>, <code>"function"</code>
|
||||||
or <code>"object"</code>.
|
or <code>"object"</code>.
|
||||||
section <s|u> Section in the file
|
section <s|u> Section in the file
|
||||||
source <s> Source code
|
source <[o]> Source code (array of tokens)
|
||||||
|
column <n> Column
|
||||||
|
line <n> Line
|
||||||
|
type <s> Type (see Ox.tokenize for a list of types)
|
||||||
|
value <s> Value
|
||||||
summary <s> One-line summary
|
summary <s> One-line summary
|
||||||
usage <[o]> Usage (array of doc objects)
|
usage <[o]> Usage (array of doc objects)
|
||||||
Present if the <code>type</code> of the item is
|
Present if the <code>type</code> of the item is
|
||||||
|
@ -156,9 +160,7 @@ Ox.doc = (function() {
|
||||||
if (/^[A-Z]/.test(item.name)) {
|
if (/^[A-Z]/.test(item.name)) {
|
||||||
// main item
|
// main item
|
||||||
// include leading whitespace
|
// include leading whitespace
|
||||||
item.source = parseTokens(tokens[i]).map(function(token) {
|
item.source = parseTokens(tokens[i]);
|
||||||
return token.value;
|
|
||||||
}).join('');
|
|
||||||
item.line = source.slice(0, item.source[0].offset)
|
item.line = source.slice(0, item.source[0].offset)
|
||||||
.split('\n').length;
|
.split('\n').length;
|
||||||
items.push(item);
|
items.push(item);
|
||||||
|
|
Loading…
Reference in a new issue