add method source to parent source; strip leading and trailing newlines
This commit is contained in:
parent
b1d171282c
commit
72d3ec87c2
2 changed files with 28 additions and 14 deletions
|
@ -86,8 +86,8 @@ Ox.DocPage = function(options, self) {
|
||||||
.css({marginLeft: ((level * 32 + 32) + 'px')})
|
.css({marginLeft: ((level * 32 + 32) + 'px')})
|
||||||
.html(
|
.html(
|
||||||
'<code><b>></b> ' +
|
'<code><b>></b> ' +
|
||||||
//Ox.encodeHTML(example.statement)
|
Ox.encodeHTML(example.statement)
|
||||||
example.statement
|
//example.statement
|
||||||
.replace(/ /g, ' ')
|
.replace(/ /g, ' ')
|
||||||
.replace(/\n/g, '<br/>\n ') +
|
.replace(/\n/g, '<br/>\n ') +
|
||||||
'</code>'
|
'</code>'
|
||||||
|
@ -103,18 +103,12 @@ Ox.DocPage = function(options, self) {
|
||||||
});
|
});
|
||||||
} else if (section == 'source') {
|
} else if (section == 'source') {
|
||||||
var html = '';
|
var html = '';
|
||||||
var flag = false;
|
|
||||||
item.source.forEach(function(token) {
|
item.source.forEach(function(token) {
|
||||||
if (token.type != 'linebreak' && token.type != 'whitespace') {
|
html += '<span class="Ox' + Ox.toTitleCase(token.type) + '">' +
|
||||||
flag = true;
|
Ox.encodeHTML(token.source)
|
||||||
}
|
.replace(/ /g, ' ')
|
||||||
if (flag) {
|
.replace(/\n/g, '<br/>') +
|
||||||
html += '<span class="Ox' + Ox.toTitleCase(token.type) + '">' +
|
'</span>';
|
||||||
Ox.encodeHTML(token.source)
|
|
||||||
.replace(/ /g, ' ')
|
|
||||||
.replace(/\n/g, '<br/>') +
|
|
||||||
'</span>';
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
$elements.push($('<div>')
|
$elements.push($('<div>')
|
||||||
.addClass('OxSourceCode ' + className)
|
.addClass('OxSourceCode ' + className)
|
||||||
|
|
22
source/Ox.js
22
source/Ox.js
|
@ -200,13 +200,33 @@ Ox.doc = (function() {
|
||||||
.replace(re.test, encodeLinebreaks)
|
.replace(re.test, encodeLinebreaks)
|
||||||
.split('\n');
|
.split('\n');
|
||||||
// create a tree and parse its root node
|
// 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)) {
|
if (/^[A-Z]/.test(item.name)) {
|
||||||
items.push(item);
|
items.push(item);
|
||||||
} else {
|
} else {
|
||||||
lastItem = items[items.length - 1];
|
lastItem = items[items.length - 1];
|
||||||
lastItem.properties = lastItem.properties || [];
|
lastItem.properties = lastItem.properties || [];
|
||||||
lastItem.properties.push(item);
|
lastItem.properties.push(item);
|
||||||
|
lastItem.source = Ox.merge(lastItem.source, item.source);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
function decodeLinebreaks(match, submatch) {
|
function decodeLinebreaks(match, submatch) {
|
||||||
|
|
Loading…
Reference in a new issue