diff --git a/demos/doc2/js/doc.js b/demos/doc2/js/doc.js index 0bd33171..2d9a045f 100644 --- a/demos/doc2/js/doc.js +++ b/demos/doc2/js/doc.js @@ -22,7 +22,7 @@ Ox.load('UI', { }, getSection: function(item) { var file = item.file.replace(Ox.PATH, ''); - return item.section || file.split('/')[2]; + return item.section || file.split('/')[2].split('.')[0]; }, path: Ox.PATH }).bindEvent({ diff --git a/source/Ox/js/JavaScript.js b/source/Ox/js/JavaScript.js index c9d2661e..c4e8da28 100644 --- a/source/Ox/js/JavaScript.js +++ b/source/Ox/js/JavaScript.js @@ -133,19 +133,35 @@ Ox.doc = (function() { result: lines[1].trim() }; } - function parseTokens(tokens, includeLeading) { - // fixme: do not strip whitespace from the beginning of the first line of the items' source - var leading = [], - tokens_ = []; + function parseTokens(tokens, includeLeadingLinebreaks) { + var isLeading = true, + isTrailing = false, + tokens_ = [], + types = ['linebreak', 'whitespace']; tokens.forEach(function(token) { - if (['linebreak', 'whitespace'].indexOf(token.type) > -1) { - includeLeading && leading.push(token); + if (isLeading && types.indexOf(token.type) > -1) { + if (token.type == 'linebreak') { + if (includeLeadingLinebreaks) { + tokens_.push(token); + } else { + tokens_ = []; + } + } else { + tokens_.push(token); + } } else { - tokens_ = Ox.merge(tokens_, leading, [token]); - leading = []; - includeLeading = true; + tokens_.push(token); + isLeading = false; + if (types.indexOf(token.type) == -1) { + isTrailing = true; + } } }); + if (isTrailing) { + while (types.indexOf(tokens_[tokens_.length - 1].type) > -1) { + tokens_.pop(); + } + } return tokens_; } function parseTree(lines) { @@ -262,6 +278,7 @@ Ox.doc = (function() { } if (/^[A-Z]/.test(item.name)) { // main item + // include leading whitespace item.source = parseTokens(tokens[i]); item.line = source.substr(0, item.source[0].offset) .split('\n').length;