1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-23 10:07:19 +00:00

Added plain text rendering of tiddlers

This commit is contained in:
Jeremy Ruston 2011-12-06 09:27:39 +00:00
parent e3b1def010
commit 87aa8667ec
2 changed files with 22 additions and 1 deletions

View File

@ -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)});

View File

@ -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));
}