From 32514df9f3e69641433463ee76e5fb29e02b5776 Mon Sep 17 00:00:00 2001 From: Jeremy Ruston Date: Fri, 9 Dec 2011 18:29:29 +0000 Subject: [PATCH] Refactored wiki text rendering --- js/Recipe.js | 13 ++- js/WikiTextMacros.js | 111 ---------------------- js/WikiTextParser.js | 100 +------------------ js/WikiTextRenderer.js | 211 +++++++++++++++++++++++++++++++++++++++++ wikitest.js | 12 ++- 5 files changed, 228 insertions(+), 219 deletions(-) delete mode 100644 js/WikiTextMacros.js create mode 100644 js/WikiTextRenderer.js diff --git a/js/Recipe.js b/js/Recipe.js index 7a521729e..fb3b0ccd6 100755 --- a/js/Recipe.js +++ b/js/Recipe.js @@ -50,6 +50,7 @@ At this point tiddlers are placed in the store so that they can be referenced by "use strict"; var Tiddler = require("./Tiddler.js").Tiddler, + WikiTextRenderer = require("./WikiTextRenderer").WikiTextRenderer, tiddlerInput = require("./TiddlerInput.js"), tiddlerOutput = require("./TiddlerOutput.js"), utils = require("./Utils.js"), @@ -282,13 +283,17 @@ Recipe.prototype.cookRss = function() numRssItems = 20, s = [], d = new Date(), - u = this.store.getTiddler("SiteUrl").getParseTree().render("text/plain",me.store,"SiteUrl"), + renderTiddler = function(title,type) { + var r = new WikiTextRenderer(me.store.getTiddler(title).getParseTree(),me.store,title); + return r.render(type); + }, + u = renderTiddler("SiteUrl","text/plain"), encodeTiddlyLink = function(title) { return title.indexOf(" ") == -1 ? title : "[[" + title + "]]"; }, tiddlerToRssItem = function(tiddler,uri) { var s = "" + utils.htmlEncode(tiddler.fields.title) + "\n"; - s += "" + utils.htmlEncode(tiddler.getParseTree().render("text/html",me.store,tiddler.fields.title)) + "\n"; + s += "" + utils.htmlEncode(renderTiddler(tiddler.fields.title,"text/plain")) + "\n"; var i; if(tiddler.fields.tags) { for(i=0; i"); s.push(""); s.push(""); - s.push("" + utils.htmlEncode(this.store.getTiddler("SiteTitle").getParseTree().render("text/plain",me.store,"SiteTitle")) + ""); + s.push("" + utils.htmlEncode(renderTiddler("SiteTitle","text/plain")) + ""); if(u) s.push("" + utils.htmlEncode(u) + ""); - s.push("" + utils.htmlEncode(this.store.getTiddler("SiteSubtitle").getParseTree().render("text/plain",me.store,"SiteSubtitle")) + ""); + s.push("" + utils.htmlEncode(renderTiddler("SiteSubtitle","text/plain")) + ""); //s.push("" + config.locale + ""); s.push("" + d.toUTCString() + ""); s.push("" + d.toUTCString() + ""); diff --git a/js/WikiTextMacros.js b/js/WikiTextMacros.js deleted file mode 100644 index 6ae7822f3..000000000 --- a/js/WikiTextMacros.js +++ /dev/null @@ -1,111 +0,0 @@ -/* -Wiki text macro implementation -*/ - -/*jslint node: true */ -"use strict"; - -var ArgParser = require("./ArgParser.js").ArgParser, - WikiTextParserModule = require("./WikiTextParser.js"), - utils = require("./Utils.js"), - util = require("util"); - -var wikiTextMacros = exports; - -wikiTextMacros.versionTiddlyWiki = "2.6.5"; - -wikiTextMacros.executeMacros = function(tree,store,title) { - for(var t=0; t"); - if(!selfClosing) { - if(element.children) { - renderSubTree(element.children); - } - output.push(""); - } - }; - renderSubTree = function(tree) { - for(var t=0; t"); + if(!selfClosing) { + if(element.children) { + renderSubTree(element.children); + } + output.push(""); + } + }; + renderSubTree = function(tree) { + for(var t=0; t.html` and `.txt`. var Tiddler = require("./js/Tiddler.js").Tiddler, WikiStore = require("./js/WikiStore.js").WikiStore, + WikiTextRenderer = require("./js/WikiTextRenderer.js").WikiTextRenderer, tiddlerInput = require("./js/TiddlerInput"), utils = require("./js/Utils.js"), util = require("util"), @@ -39,11 +40,12 @@ for(f=0; f