add method source to parent source; strip leading and trailing newlines

This commit is contained in:
rolux 2011-05-06 20:01:34 +02:00
parent b1d171282c
commit 72d3ec87c2
2 changed files with 28 additions and 14 deletions

View file

@ -86,8 +86,8 @@ Ox.DocPage = function(options, self) {
.css({marginLeft: ((level * 32 + 32) + 'px')})
.html(
'<code><b>&gt;</b>&nbsp;' +
//Ox.encodeHTML(example.statement)
example.statement
Ox.encodeHTML(example.statement)
//example.statement
.replace(/ /g, '&nbsp;')
.replace(/\n/g, '<br/>\n&nbsp;&nbsp;') +
'</code>'
@ -103,18 +103,12 @@ Ox.DocPage = function(options, self) {
});
} else if (section == 'source') {
var html = '';
var flag = false;
item.source.forEach(function(token) {
if (token.type != 'linebreak' && token.type != 'whitespace') {
flag = true;
}
if (flag) {
html += '<span class="Ox' + Ox.toTitleCase(token.type) + '">' +
Ox.encodeHTML(token.source)
.replace(/ /g, '&nbsp;')
.replace(/\n/g, '<br/>') +
'</span>';
}
html += '<span class="Ox' + Ox.toTitleCase(token.type) + '">' +
Ox.encodeHTML(token.source)
.replace(/ /g, '&nbsp;')
.replace(/\n/g, '<br/>') +
'</span>';
});
$elements.push($('<div>')
.addClass('OxSourceCode ' + className)

View file

@ -200,13 +200,33 @@ Ox.doc = (function() {
.replace(re.test, encodeLinebreaks)
.split('\n');
// create a tree and parse its root node
item = Ox.extend(parseNode(parseTree(lines)), {source: tokens[i]});
item = parseNode(parseTree(lines));
///*
item.source = [];
var tokenBuffer = [], tokenFlag = false;
tokens[i].forEach(function(token) {
if (['linebreak', 'whitespace'].indexOf(token.type) > -1) {
tokenBuffer.push(token);
} else {
if (!tokenFlag) {
item.source.push(token);
tokenFlag = true;
} else {
item.source = Ox.merge(item.source, tokenBuffer, [token]);
}
tokenBuffer = [];
}
});
//*/
if (/^[A-Z]/.test(item.name)) {
items.push(item);
} else {
lastItem = items[items.length - 1];
lastItem.properties = lastItem.properties || [];
lastItem.properties.push(item);
lastItem.source = Ox.merge(lastItem.source, item.source);
}
});
function decodeLinebreaks(match, submatch) {