diff --git a/js/WikiStore.js b/js/WikiStore.js index 5722b255a..844cf50bf 100755 --- a/js/WikiStore.js +++ b/js/WikiStore.js @@ -314,15 +314,18 @@ store.renderTiddler("text/html",templateTitle,tiddlerTitle) WikiStore.prototype.renderTiddler = function(type,title,asTitle) { var tiddler = this.getTiddler(title), fn = this.compileTiddler(title,type); - if(asTitle) { - var asTiddler = this.getTiddler(asTitle); - return fn(asTiddler,this,utils); - } else { - if(!tiddler.renditions[type]) { - tiddler.renditions[type] = fn(tiddler,this,utils); + if(tiddler) { + if(asTitle) { + var asTiddler = this.getTiddler(asTitle); + return fn(asTiddler,this,utils); + } else { + if(!tiddler.renditions[type]) { + tiddler.renditions[type] = fn(tiddler,this,utils); + } + return tiddler.renditions[type]; } - return tiddler.renditions[type]; } + return null; }; WikiStore.prototype.installMacros = function() { diff --git a/js/WikiTextParseTree.js b/js/WikiTextParseTree.js index 497494335..fdc893014 100644 --- a/js/WikiTextParseTree.js +++ b/js/WikiTextParseTree.js @@ -76,32 +76,10 @@ WikiTextParseTree.prototype.pushString = function(s) { }; WikiTextParseTree.prototype.compileMacroCall = function(type,name,params) { - var me = this, - macro = this.store.macros[name]; + var macro = this.store.macros[name], + p, + n; if(macro) { - var args = new ArgParser(params,{defaultName: "anon"}), - paramsProps = {}; - var insertParam = function(name,arg) { - if(arg.evaluated) { - paramsProps[name] = me.store.jsParser.parse(arg.string).tree.elements[0]; - } else { - paramsProps[name] = {type: "StringLiteral", value: arg.string}; - } - }; - for(var m in macro.params) { - var param = macro.params[m]; - if("byPos" in param && args.byPos[param.byPos]) { - insertParam(m,args.byPos[param.byPos].v); - } else if("byName" in param) { - var arg = args.getValueByName(m); - if(!arg && param.byName === "default") { - arg = args.getValueByName("anon"); - } - if(arg) { - insertParam(m,arg); - } - } - } var macroCall = { type: "FunctionCall", name: { @@ -115,11 +93,16 @@ WikiTextParseTree.prototype.compileMacroCall = function(type,name,params) { }] }; macroCall.name.elements = macro.code[type].tree.elements; - for(m in paramsProps) { + for(p in params) { + if(params[p].type === "string") { + n = {type: "StringLiteral", value: params[p].value}; + } else { + n = this.store.jsParser.parse(params[p].value).tree.elements[0]; + } macroCall["arguments"][0].properties.push({ type: "PropertyAssignment", - name: m, - value: paramsProps[m] + name: p, + value: n }); } this.output.push(macroCall); diff --git a/js/WikiTextRules.js b/js/WikiTextRules.js index dc4b01846..1864c3c85 100755 --- a/js/WikiTextRules.js +++ b/js/WikiTextRules.js @@ -7,7 +7,8 @@ title: js/WikiTextRules.js /*jslint node: true */ "use strict"; -var util = require("util"); +var ArgParser = require("./ArgParser.js").ArgParser, + util = require("util"); var textPrimitives = { upperLetter: "[A-Z\u00c0-\u00de\u0150\u0170]", @@ -107,6 +108,32 @@ var enclosedTextHelper = function(w) { } }; +var parseMacroCall = function(w,name,paramString) { + var macro = w.store.macros[name], + params = {}; + if(macro) { + var args = new ArgParser(paramString,{defaultName: "anon"}), + insertParam = function(name,arg) { + params[name] = {type: arg.evaluated ? "eval" : "string", value: arg.string}; + }; + for(var m in macro.params) { + var param = macro.params[m]; + if("byPos" in param && args.byPos[param.byPos]) { + insertParam(m,args.byPos[param.byPos].v); + } else if("byName" in param) { + var arg = args.getValueByName(m); + if(!arg && param.byName === "default") { + arg = args.getValueByName("anon"); + } + if(arg) { + insertParam(m,arg); + } + } + } + } + return {type: "macro", name: name, params: params}; +}; + var rules = [ { name: "table", @@ -410,7 +437,7 @@ var rules = [ var lookaheadMatch = this.lookaheadRegExp.exec(w.source); if(lookaheadMatch && lookaheadMatch.index == w.matchStart && lookaheadMatch[1]) { w.nextMatch = this.lookaheadRegExp.lastIndex; - w.output.push({type: "macro", name: lookaheadMatch[1], params: lookaheadMatch[2]}); + w.output.push(parseMacroCall(w,lookaheadMatch[1],lookaheadMatch[2])); } } },