Added plain text rendering of tiddlers

print-window-tiddler
Jeremy Ruston 2011-12-06 09:27:39 +00:00
rodzic e3b1def010
commit 87aa8667ec
2 zmienionych plików z 22 dodań i 1 usunięć

Wyświetl plik

@ -47,6 +47,8 @@ var WikiTextParser = function(text) {
WikiTextParser.prototype.render = function(type,store,title) {
if(type === "text/html") {
return this.renderAsHtml(store,title);
} else if (type === "text/plain") {
return this.renderAsText(store,title);
} else {
return null;
}
@ -89,6 +91,22 @@ WikiTextParser.prototype.renderAsHtml = function(store,title) {
return output.join("");
};
WikiTextParser.prototype.renderAsText = function(store,title) {
var output = [];
var renderSubTree = function(tree) {
for(var t=0; t<tree.length; t++) {
if(tree[t].type === "text") {
output.push(tree[t].value);
}
if(tree[t].children) {
renderSubTree(tree[t].children);
}
}
};
renderSubTree(this.tree);
return output.join("");
};
WikiTextParser.prototype.outputText = function(place,startPos,endPos) {
if(startPos < endPos) {
place.push({type: "text", value: this.source.substring(startPos,endPos)});

Wyświetl plik

@ -16,7 +16,10 @@ var wikiTest = function(spec) {
var tid = new Tiddler(spec.tiddlers[t]);
store.addTiddler(tid);
console.error("%s in HTML:\n%s",tid.fields.title,tid.getParseTree().render("text/html",store,tid.fields.title));
console.error("%s in HTML:\n%s\nAnd in plain:\n%s",
tid.fields.title,
tid.getParseTree().render("text/html",store,tid.fields.title),
tid.getParseTree().render("text/plain",store,tid.fields.title));
}