diff --git a/core/modules/filterrunprefixes/cascade.js b/core/modules/filterrunprefixes/cascade.js index da6894d21..486e75f45 100644 --- a/core/modules/filterrunprefixes/cascade.js +++ b/core/modules/filterrunprefixes/cascade.js @@ -25,20 +25,10 @@ exports.cascade = function(operationSubFunction,options) { if(!filterFnList[index]) { filterFnList[index] = options.wiki.compileFilter(filter); } - var output = filterFnList[index](options.wiki.makeTiddlerIterator([title]),{ - getVariable: function(name,opts) { - opts = opts || {}; - opts.variables = { - "currentTiddler": "" + title, - "..currentTiddler": widget.getVariable("currentTiddler") - }; - if(name in opts.variables) { - return opts.variables[name]; - } else { - return widget.getVariable(name,opts); - } - } - }); + var output = filterFnList[index](options.wiki.makeTiddlerIterator([title]),widget.makeFakeWidgetWithVariables({ + "currentTiddler": "" + title, + "..currentTiddler": widget.getVariable("currentTiddler","") + })); if(output.length !== 0) { result = output[0]; return false; diff --git a/core/modules/filterrunprefixes/filter.js b/core/modules/filterrunprefixes/filter.js index 783b699c2..4ab057109 100644 --- a/core/modules/filterrunprefixes/filter.js +++ b/core/modules/filterrunprefixes/filter.js @@ -19,23 +19,13 @@ exports.filter = function(operationSubFunction,options) { var resultsToRemove = [], index = 0; results.each(function(title) { - var filtered = operationSubFunction(options.wiki.makeTiddlerIterator([title]),{ - getVariable: function(name,opts) { - opts = opts || {}; - opts.variables = { - "currentTiddler": "" + title, - "..currentTiddler": widget.getVariable("currentTiddler"), - "index": "" + index, - "revIndex": "" + (results.length - 1 - index), - "length": "" + results.length - }; - if(name in opts.variables) { - return opts.variables[name]; - } else { - return widget.getVariable(name,opts); - } - } - }); + var filtered = operationSubFunction(options.wiki.makeTiddlerIterator([title]),widget.makeFakeWidgetWithVariables({ + "currentTiddler": "" + title, + "..currentTiddler": widget.getVariable("currentTiddler",""), + "index": "" + index, + "revIndex": "" + (results.length - 1 - index), + "length": "" + results.length + })); if(filtered.length === 0) { resultsToRemove.push(title); } diff --git a/core/modules/filterrunprefixes/map.js b/core/modules/filterrunprefixes/map.js index efcb5b534..b756d6699 100644 --- a/core/modules/filterrunprefixes/map.js +++ b/core/modules/filterrunprefixes/map.js @@ -21,23 +21,13 @@ exports.map = function(operationSubFunction,options) { flatten = (suffixes[0] && suffixes[0][0] === "flat") ? true : false; results.clear(); $tw.utils.each(inputTitles,function(title) { - var filtered = operationSubFunction(options.wiki.makeTiddlerIterator([title]),{ - getVariable: function(name,opts) { - opts = opts || {}; - opts.variables = { - "currentTiddler": "" + title, - "..currentTiddler": widget.getVariable("currentTiddler"), - "index": "" + index, - "revIndex": "" + (inputTitles.length - 1 - index), - "length": "" + inputTitles.length - }; - if(name in opts.variables) { - return opts.variables[name]; - } else { - return widget.getVariable(name,opts); - } - } - }); + var filtered = operationSubFunction(options.wiki.makeTiddlerIterator([title]),widget.makeFakeWidgetWithVariables({ + "currentTiddler": "" + title, + "..currentTiddler": widget.getVariable("currentTiddler",""), + "index": "" + index, + "revIndex": "" + (inputTitles.length - 1 - index), + "length": "" + inputTitles.length + })); if(filtered.length && flatten) { $tw.utils.each(filtered,function(value) { results.push(value); diff --git a/core/modules/filterrunprefixes/reduce.js b/core/modules/filterrunprefixes/reduce.js index 8fe819e3f..ee2998837 100644 --- a/core/modules/filterrunprefixes/reduce.js +++ b/core/modules/filterrunprefixes/reduce.js @@ -18,24 +18,14 @@ exports.reduce = function(operationSubFunction,options) { var accumulator = "", index = 0; results.each(function(title) { - var list = operationSubFunction(options.wiki.makeTiddlerIterator([title]),{ - getVariable: function(name,opts) { - opts = opts || {}; - opts.variables = { - "currentTiddler": "" + title, - "..currentTiddler": widget.getVariable("currentTiddler"), - "index": "" + index, - "revIndex": "" + (results.length - 1 - index), - "length": "" + results.length, - "accumulator": "" + accumulator - }; - if(name in opts.variables) { - return opts.variables[name]; - } else { - return widget.getVariable(name,opts); - } - } - }); + var list = operationSubFunction(options.wiki.makeTiddlerIterator([title]),widget.makeFakeWidgetWithVariables({ + "currentTiddler": "" + title, + "..currentTiddler": widget.getVariable("currentTiddler"), + "index": "" + index, + "revIndex": "" + (results.length - 1 - index), + "length": "" + results.length, + "accumulator": "" + accumulator + })); if(list.length > 0) { accumulator = "" + list[0]; } diff --git a/core/modules/filterrunprefixes/sort.js b/core/modules/filterrunprefixes/sort.js index 6865b175c..d8d376126 100644 --- a/core/modules/filterrunprefixes/sort.js +++ b/core/modules/filterrunprefixes/sort.js @@ -25,20 +25,10 @@ exports.sort = function(operationSubFunction,options) { indexes = new Array(inputTitles.length), compareFn; results.each(function(title) { - var key = operationSubFunction(options.wiki.makeTiddlerIterator([title]),{ - getVariable: function(name,opts) { - opts = opts || {}; - opts.variables = { - "currentTiddler": "" + title, - "..currentTiddler": widget.getVariable("currentTiddler") - }; - if(name in opts.variables) { - return opts.variables[name]; - } else { - return widget.getVariable(name,opts); - } - } - }); + var key = operationSubFunction(options.wiki.makeTiddlerIterator([title]),widget.makeFakeWidgetWithVariables({ + "currentTiddler": "" + title, + "..currentTiddler": widget.getVariable("currentTiddler") + })); sortKeys.push(key[0] || ""); }); results.clear(); diff --git a/core/modules/filters.js b/core/modules/filters.js index 1bb5fe9ff..b705c994c 100644 --- a/core/modules/filters.js +++ b/core/modules/filters.js @@ -255,19 +255,21 @@ exports.compileFilter = function(filterString) { var operands = [], operatorFunction; if(!operator.operator) { + // Use the "title" operator if no operator is specified operatorFunction = filterOperators.title; } else if(!filterOperators[operator.operator]) { - operatorFunction = filterOperators.field; + // Unknown operators treated as "[unknown]" - at run time we can distinguish between a custom operator and falling back to the default "field" operator + operatorFunction = filterOperators["[unknown]"]; } else { + // Use the operator function operatorFunction = filterOperators[operator.operator]; } - $tw.utils.each(operator.operands,function(operand) { if(operand.indirect) { operand.value = self.getTextReference(operand.text,"",currTiddlerTitle); } else if(operand.variable) { var varTree = $tw.utils.parseFilterVariable(operand.text); - operand.value = widget.getVariable(varTree.name,{params:varTree.params,defaultValue: ""}); + operand.value = widget.evaluateVariable(varTree.name,{params: varTree.params, source: source})[0] || ""; } else { operand.value = operand.text; } diff --git a/core/modules/filters/filter.js b/core/modules/filters/filter.js index 9b69fd83a..f15cbefc5 100644 --- a/core/modules/filters/filter.js +++ b/core/modules/filters/filter.js @@ -20,19 +20,10 @@ exports.filter = function(source,operator,options) { results = [], target = operator.prefix !== "!"; source(function(tiddler,title) { - var list = filterFn.call(options.wiki,options.wiki.makeTiddlerIterator([title]),{ - getVariable: function(name,opts) { - opts = opts || {}; - switch(name) { - case "currentTiddler": - return "" + title; - case "..currentTiddler": - return options.widget.getVariable("currentTiddler"); - default: - return options.widget.getVariable(name,opts); - } - } - }); + var list = filterFn.call(options.wiki,options.wiki.makeTiddlerIterator([title]),options.widget.makeFakeWidgetWithVariables({ + "currentTiddler": "" + title, + "..currentTiddler": options.widget.getVariable("currentTiddler","") + })); if((list.length > 0) === target) { results.push(title); } diff --git a/core/modules/filters/function.js b/core/modules/filters/function.js new file mode 100644 index 000000000..f6a8c034d --- /dev/null +++ b/core/modules/filters/function.js @@ -0,0 +1,32 @@ +/*\ +title: $:/core/modules/filters/function.js +type: application/javascript +module-type: filteroperator + +Filter operator returning those input titles that are returned from a function + +\*/ +(function(){ + +/*jslint node: true, browser: true */ +/*global $tw: false */ +"use strict"; + +/* +Export our filter function +*/ +exports.function = function(source,operator,options) { + var functionName = operator.operands[0], + variableInfo = options.widget && options.widget.getVariableInfo && options.widget.getVariableInfo(functionName); + if(variableInfo && variableInfo.srcVariable && variableInfo.srcVariable.isFunctionDefinition) { + return options.widget.evaluateVariable(functionName,{params: operator.operands.slice(1), source: source}); + } + // Return the input list if the function wasn't found + var results = []; + source(function(tiddler,title) { + results.push(title); + }); + return results; +}; + +})(); diff --git a/core/modules/filters/reduce.js b/core/modules/filters/reduce.js index 50c501f08..efe8aea4a 100644 --- a/core/modules/filters/reduce.js +++ b/core/modules/filters/reduce.js @@ -26,27 +26,14 @@ exports.reduce = function(source,operator,options) { accumulator = operator.operands[1] || ""; for(var index=0; index 0) { accumulator = "" + list[0]; } diff --git a/core/modules/filters/sortsub.js b/core/modules/filters/sortsub.js index e9f676daa..d328be09c 100644 --- a/core/modules/filters/sortsub.js +++ b/core/modules/filters/sortsub.js @@ -25,19 +25,10 @@ exports.sortsub = function(source,operator,options) { inputTitles.push(title); var r = filterFn.call(options.wiki,function(iterator) { iterator(options.wiki.getTiddler(title),title); - },{ - getVariable: function(name,opts) { - opts = opts || {}; - switch(name) { - case "currentTiddler": - return "" + title; - case "..currentTiddler": - return options.widget.getVariable("currentTiddler"); - default: - return options.widget.getVariable(name,opts); - } - } - }); + },options.widget.makeFakeWidgetWithVariables({ + "currentTiddler": "" + title, + "..currentTiddler": options.widget.getVariable("currentTiddler") + })); sortKeys.push(r[0] || ""); }); // Rather than sorting the titles array, we'll sort the indexes so that we can consult both arrays diff --git a/core/modules/filters/unknown.js b/core/modules/filters/unknown.js new file mode 100644 index 000000000..21856766b --- /dev/null +++ b/core/modules/filters/unknown.js @@ -0,0 +1,45 @@ +/*\ +title: $:/core/modules/filters/unknown.js +type: application/javascript +module-type: filteroperator + +Filter operator for handling unknown filter operators. + +Not intended to be used directly by end users, hence the square brackets around the name. + +\*/ +(function(){ + +/*jslint node: true, browser: true */ +/*global $tw: false */ +"use strict"; + +var fieldFilterOperatorFn = require("$:/core/modules/filters/field.js").field; + +/* +Export our filter function +*/ +exports["[unknown]"] = function(source,operator,options) { + // Check for a user defined filter operator + if(operator.operator.charAt(0) === ".") { + var variableInfo = options.widget && options.widget.getVariableInfo && options.widget.getVariableInfo(operator.operator); + if(variableInfo && variableInfo.srcVariable && variableInfo.srcVariable.isFunctionDefinition) { + var list = options.widget.evaluateVariable(operator.operator,{params: operator.operands, source: source}); + if(operator.prefix === "!") { + var results = []; + source(function(tiddler,title) { + if(list.indexOf(title) === -1) { + results.push(title); + } + }); + return results; + } else { + return list; + } + } + } + // Otherwise, use the "field" operator + return fieldFilterOperatorFn(source,operator,options); +}; + +})(); diff --git a/core/modules/parsers/audioparser.js b/core/modules/parsers/audioparser.js index 95380bf80..5eb2ff985 100644 --- a/core/modules/parsers/audioparser.js +++ b/core/modules/parsers/audioparser.js @@ -28,6 +28,8 @@ var AudioParser = function(type,text,options) { element.attributes.src = {type: "string", value: "data:" + type + ";base64," + text}; } this.tree = [element]; + this.source = text; + this.type = type; }; exports["audio/ogg"] = AudioParser; diff --git a/core/modules/parsers/binaryparser.js b/core/modules/parsers/binaryparser.js index fb3d38678..60e7b5ef0 100644 --- a/core/modules/parsers/binaryparser.js +++ b/core/modules/parsers/binaryparser.js @@ -23,7 +23,7 @@ var BinaryParser = function(type,text,options) { children: [{ type: "transclude", attributes: { - tiddler: {type: "string", value: BINARY_WARNING_MESSAGE} + "$tiddler": {type: "string", value: BINARY_WARNING_MESSAGE} } }] }; @@ -38,7 +38,7 @@ var BinaryParser = function(type,text,options) { children: [{ type: "transclude", attributes: { - tiddler: {type: "string", value: EXPORT_BUTTON_IMAGE} + "$tiddler": {type: "string", value: EXPORT_BUTTON_IMAGE} } }] }; @@ -64,6 +64,8 @@ var BinaryParser = function(type,text,options) { children: [warn, link] } this.tree = [element]; + this.source = text; + this.type = type; }; exports["application/octet-stream"] = BinaryParser; diff --git a/core/modules/parsers/csvparser.js b/core/modules/parsers/csvparser.js index 40431d0ae..f40b5f0e5 100644 --- a/core/modules/parsers/csvparser.js +++ b/core/modules/parsers/csvparser.js @@ -52,6 +52,8 @@ var CsvParser = function(type,text,options) { tag = "td"; this.tree[0].children[0].children[0].children.push(row); } + this.source = text; + this.type = type; }; exports["text/csv"] = CsvParser; diff --git a/core/modules/parsers/htmlparser.js b/core/modules/parsers/htmlparser.js index 206ab9c78..24c9f5d3e 100644 --- a/core/modules/parsers/htmlparser.js +++ b/core/modules/parsers/htmlparser.js @@ -29,6 +29,8 @@ var HtmlParser = function(type,text,options) { if($tw.wiki.getTiddlerText("$:/config/HtmlParser/DisableSandbox","no") !== "yes") { this.tree[0].attributes.sandbox = {type: "string", value: $tw.wiki.getTiddlerText("$:/config/HtmlParser/SandboxTokens","")}; } + this.source = text; + this.type = type; }; exports["text/html"] = HtmlParser; diff --git a/core/modules/parsers/imageparser.js b/core/modules/parsers/imageparser.js index e3b8fb60a..a964a4ba8 100644 --- a/core/modules/parsers/imageparser.js +++ b/core/modules/parsers/imageparser.js @@ -28,6 +28,8 @@ var ImageParser = function(type,text,options) { } } this.tree = [element]; + this.source = text; + this.type = type; }; exports["image/svg+xml"] = ImageParser; diff --git a/core/modules/parsers/parseutils.js b/core/modules/parsers/parseutils.js index 925674056..6a0902c6f 100644 --- a/core/modules/parsers/parseutils.js +++ b/core/modules/parsers/parseutils.js @@ -123,6 +123,36 @@ exports.parseStringLiteral = function(source,pos) { } }; +/* +Returns an array of {name:} with an optional "default" property. Options include: +requireParenthesis: require the parameter definition to be wrapped in parenthesis +*/ +exports.parseParameterDefinition = function(paramString,options) { + options = options || {}; + if(options.requireParenthesis) { + var parenMatch = /^\s*\((.*)\)\s*$/g.exec(paramString); + if(!parenMatch) { + return []; + } + paramString = parenMatch[1]; + } + var params = [], + reParam = /\s*([^:),\s]+)(?:\s*:\s*(?:"""([\s\S]*?)"""|"([^"]*)"|'([^']*)'|([^,"'\s]+)))?/mg, + paramMatch = reParam.exec(paramString); + while(paramMatch) { + // Save the parameter details + var paramInfo = {name: paramMatch[1]}, + defaultValue = paramMatch[2] || paramMatch[3] || paramMatch[4] || paramMatch[5]; + if(defaultValue !== undefined) { + paramInfo["default"] = defaultValue; + } + params.push(paramInfo); + // Look for the next parameter + paramMatch = reParam.exec(paramString); + } + return params; +}; + exports.parseMacroParameters = function(node,source,pos) { // Process parameters var parameter = $tw.utils.parseMacroParameter(source,pos); @@ -175,7 +205,36 @@ exports.parseMacroParameter = function(source,pos) { }; /* -Look for a macro invocation. Returns null if not found, or {type: "macrocall", name:, parameters:, start:, end:} +Look for a macro invocation. Returns null if not found, or {type: "transclude", attributes:, start:, end:} +*/ +exports.parseMacroInvocationAsTransclusion = function(source,pos) { + var node = $tw.utils.parseMacroInvocation(source,pos); + if(node) { + var positionalName = 0, + transclusion = { + type: "transclude", + start: node.start, + end: node.end + }; + $tw.utils.addAttributeToParseTreeNode(transclusion,"$variable",node.name); + $tw.utils.each(node.params,function(param) { + var name = param.name; + if(name) { + if(name.charAt(0) === "$") { + name = "$" + name; + } + $tw.utils.addAttributeToParseTreeNode(transclusion,{name: name,type: "string", value: param.value, start: param.start, end: param.end}); + } else { + $tw.utils.addAttributeToParseTreeNode(transclusion,{name: (positionalName++) + "",type: "string", value: param.value, start: param.start, end: param.end}); + } + }); + return transclusion; + } + return node; +}; + +/* +Look for a macro invocation. Returns null if not found, or {type: "macrocall", name:, params:, start:, end:} */ exports.parseMacroInvocation = function(source,pos) { var node = { diff --git a/core/modules/parsers/pdfparser.js b/core/modules/parsers/pdfparser.js index 19d4253d7..c7830bf69 100644 --- a/core/modules/parsers/pdfparser.js +++ b/core/modules/parsers/pdfparser.js @@ -25,6 +25,8 @@ var ImageParser = function(type,text,options) { element.attributes.src = {type: "string", value: "data:application/pdf;base64," + text}; } this.tree = [element]; + this.source = text; + this.type = type; }; exports["application/pdf"] = ImageParser; diff --git a/core/modules/parsers/textparser.js b/core/modules/parsers/textparser.js index 4f55f6f0c..06b08f30f 100644 --- a/core/modules/parsers/textparser.js +++ b/core/modules/parsers/textparser.js @@ -20,6 +20,8 @@ var TextParser = function(type,text,options) { language: {type: "string", value: type} } }]; + this.source = text; + this.type = type; }; exports["text/plain"] = TextParser; diff --git a/core/modules/parsers/videoparser.js b/core/modules/parsers/videoparser.js index f1c281c7c..1c8a38bb2 100644 --- a/core/modules/parsers/videoparser.js +++ b/core/modules/parsers/videoparser.js @@ -28,6 +28,8 @@ var VideoParser = function(type,text,options) { element.attributes.src = {type: "string", value: "data:" + type + ";base64," + text}; } this.tree = [element]; + this.source = text; + this.type = type; }; exports["video/ogg"] = VideoParser; diff --git a/core/modules/parsers/wikiparser/rules/fnprocdef.js b/core/modules/parsers/wikiparser/rules/fnprocdef.js new file mode 100644 index 000000000..5d0a8878b --- /dev/null +++ b/core/modules/parsers/wikiparser/rules/fnprocdef.js @@ -0,0 +1,97 @@ +/*\ +title: $:/core/modules/parsers/wikiparser/rules/fnprocdef.js +type: application/javascript +module-type: wikirule + +Wiki pragma rule for function, procedure and widget definitions + +``` +\function name(param:defaultvalue,param2:defaultvalue) +definition text +\end + +\procedure name(param:defaultvalue,param2:defaultvalue) +definition text +\end + +\widget $mywidget(param:defaultvalue,param2:defaultvalue) +definition text +\end +``` + +\*/ +(function(){ + +/*jslint node: true, browser: true */ +/*global $tw: false */ +"use strict"; + +exports.name = "fnprocdef"; +exports.types = {pragma: true}; + +/* +Instantiate parse rule +*/ +exports.init = function(parser) { + this.parser = parser; + // Regexp to match + this.matchRegExp = /^\\(function|procedure|widget)\s+([^(\s]+)\((\s*([^)]*))?\)(\s*\r?\n)?/mg; +}; + +/* +Parse the most recent match +*/ +exports.parse = function() { + // Move past the macro name and parameters + this.parser.pos = this.matchRegExp.lastIndex; + // Parse the parameters + var params = []; + if(this.match[3]) { + params = $tw.utils.parseParameterDefinition(this.match[4]); + } + // Is this a multiline definition? + var reEnd; + if(this.match[5]) { + // If so, the end of the body is marked with \end + reEnd = new RegExp("(\\r?\\n\\\\end[^\\S\\n\\r]*(?:" + $tw.utils.escapeRegExp(this.match[2]) + ")?(?:$|\\r?\\n))","mg"); + } else { + // Otherwise, the end of the definition is marked by the end of the line + reEnd = /($|\r?\n)/mg; + // Move past any whitespace + this.parser.pos = $tw.utils.skipWhiteSpace(this.parser.source,this.parser.pos); + } + // Find the end of the definition + reEnd.lastIndex = this.parser.pos; + var text, + endMatch = reEnd.exec(this.parser.source); + if(endMatch) { + text = this.parser.source.substring(this.parser.pos,endMatch.index); + this.parser.pos = endMatch.index + endMatch[0].length; + } else { + // We didn't find the end of the definition, so we'll make it blank + text = ""; + } + // Save the macro definition + var parseTreeNodes = [{ + type: "set", + attributes: {}, + children: [], + params: params + }]; + $tw.utils.addAttributeToParseTreeNode(parseTreeNodes[0],"name",this.match[2]); + $tw.utils.addAttributeToParseTreeNode(parseTreeNodes[0],"value",text); + if(this.match[1] === "function") { + parseTreeNodes[0].isFunctionDefinition = true; + } else if(this.match[1] === "procedure") { + parseTreeNodes[0].isProcedureDefinition = true; + } else if(this.match[1] === "widget") { + parseTreeNodes[0].isWidgetDefinition = true; + } + if(this.parser.configTrimWhiteSpace) { + parseTreeNodes[0].configTrimWhiteSpace = true; + } + return parseTreeNodes; +}; + +})(); + \ No newline at end of file diff --git a/core/modules/parsers/wikiparser/rules/html.js b/core/modules/parsers/wikiparser/rules/html.js index 7fc4bb96e..64469e3b2 100644 --- a/core/modules/parsers/wikiparser/rules/html.js +++ b/core/modules/parsers/wikiparser/rules/html.js @@ -93,9 +93,6 @@ exports.parseTag = function(source,pos,options) { return null; } node.tag = token.match[1]; - if(node.tag.slice(1).indexOf("$") !== -1) { - return null; - } if(node.tag.charAt(0) === "$") { node.type = node.tag.substr(1); } diff --git a/core/modules/parsers/wikiparser/rules/macrocallblock.js b/core/modules/parsers/wikiparser/rules/macrocallblock.js index 6f50fdbb0..a2c10e04a 100644 --- a/core/modules/parsers/wikiparser/rules/macrocallblock.js +++ b/core/modules/parsers/wikiparser/rules/macrocallblock.js @@ -27,7 +27,7 @@ exports.findNextMatch = function(startPos) { var nextStart = startPos; // Try parsing at all possible macrocall openers until we match while((nextStart = this.parser.source.indexOf("<<",nextStart)) >= 0) { - var nextCall = $tw.utils.parseMacroInvocation(this.parser.source,nextStart); + var nextCall = $tw.utils.parseMacroInvocationAsTransclusion(this.parser.source,nextStart); if(nextCall) { var c = this.parser.source.charAt(nextCall.end); // Ensure EOL after parsed macro diff --git a/core/modules/parsers/wikiparser/rules/macrocallinline.js b/core/modules/parsers/wikiparser/rules/macrocallinline.js index 165a70dce..e9f79f09e 100644 --- a/core/modules/parsers/wikiparser/rules/macrocallinline.js +++ b/core/modules/parsers/wikiparser/rules/macrocallinline.js @@ -27,7 +27,7 @@ exports.findNextMatch = function(startPos) { var nextStart = startPos; // Try parsing at all possible macrocall openers until we match while((nextStart = this.parser.source.indexOf("<<",nextStart)) >= 0) { - this.nextCall = $tw.utils.parseMacroInvocation(this.parser.source,nextStart); + this.nextCall = $tw.utils.parseMacroInvocationAsTransclusion(this.parser.source,nextStart); if(this.nextCall) { return nextStart; } diff --git a/core/modules/parsers/wikiparser/rules/macrodef.js b/core/modules/parsers/wikiparser/rules/macrodef.js index 1efd3449a..74a94a385 100644 --- a/core/modules/parsers/wikiparser/rules/macrodef.js +++ b/core/modules/parsers/wikiparser/rules/macrodef.js @@ -77,16 +77,16 @@ exports.parse = function() { text = ""; } // Save the macro definition - return [{ + var parseTreeNodes = [{ type: "set", - attributes: { - name: {type: "string", value: this.match[1]}, - value: {type: "string", value: text} - }, + attributes: {}, children: [], params: params, isMacroDefinition: true }]; + $tw.utils.addAttributeToParseTreeNode(parseTreeNodes[0],"name",this.match[1]); + $tw.utils.addAttributeToParseTreeNode(parseTreeNodes[0],"value",text); + return parseTreeNodes; }; })(); diff --git a/core/modules/parsers/wikiparser/rules/parameters.js b/core/modules/parsers/wikiparser/rules/parameters.js new file mode 100644 index 000000000..561c1c545 --- /dev/null +++ b/core/modules/parsers/wikiparser/rules/parameters.js @@ -0,0 +1,60 @@ +/*\ +title: $:/core/modules/parsers/wikiparser/rules/parameters.js +type: application/javascript +module-type: wikirule + +Wiki pragma rule for parameter definitions + +``` +\parameters(param:defaultvalue,param2:defaultvalue) +definition text +``` + +\*/ +(function(){ + +/*jslint node: true, browser: true */ +/*global $tw: false */ +"use strict"; + +exports.name = "parameters"; +exports.types = {pragma: true}; + +/* +Instantiate parse rule +*/ +exports.init = function(parser) { + this.parser = parser; + // Regexp to match + this.matchRegExp = /^\\parameters\s*\(([^)]*)\)\s*\r?\n/mg; +}; + +/* +Parse the most recent match +*/ +exports.parse = function() { + // Move past the macro name and parameters + this.parser.pos = this.matchRegExp.lastIndex; + // Parse the parameters + var params = $tw.utils.parseParameterDefinition(this.match[1]); + var attributes = Object.create(null), + orderedAttributes = []; + $tw.utils.each(params,function(param) { + var name = param.name; + // Parameter names starting with dollar must be escaped to double dollars for the parameters widget + if(name.charAt(0) === "$") { + name = "$" + name; + } + var attribute = {name: name, type: "string", value: param["default"] || ""}; + attributes[name] = attribute; + orderedAttributes.push(attribute); + }); + // Save the macro definition + return [{ + type: "parameters", + attributes: attributes, + orderedAttributes: orderedAttributes + }]; +}; + +})(); diff --git a/core/modules/parsers/wikiparser/rules/transcludeblock.js b/core/modules/parsers/wikiparser/rules/transcludeblock.js index 56a4f63b8..c033c2440 100644 --- a/core/modules/parsers/wikiparser/rules/transcludeblock.js +++ b/core/modules/parsers/wikiparser/rules/transcludeblock.js @@ -23,7 +23,7 @@ exports.types = {block: true}; exports.init = function(parser) { this.parser = parser; // Regexp to match - this.matchRegExp = /\{\{([^\{\}\|]*)(?:\|\|([^\|\{\}]+))?\}\}(?:\r?\n|$)/mg; + this.matchRegExp = /\{\{([^\{\}\|]*)(?:\|\|([^\|\{\}]+))?(?:\|([^\{\}]+))?\}\}(?:\r?\n|$)/mg; }; exports.parse = function() { @@ -31,13 +31,22 @@ exports.parse = function() { this.parser.pos = this.matchRegExp.lastIndex; // Get the match details var template = $tw.utils.trim(this.match[2]), - textRef = $tw.utils.trim(this.match[1]); + textRef = $tw.utils.trim(this.match[1]), + params = this.match[3] ? this.match[3].split("|") : []; // Prepare the transclude widget var transcludeNode = { type: "transclude", attributes: {}, isBlock: true }; + $tw.utils.each(params,function(paramValue,index) { + var name = "" + index; + transcludeNode.attributes[name] = { + name: name, + type: "string", + value: paramValue + } + }); // Prepare the tiddler widget var tr, targetTitle, targetField, targetIndex, tiddlerNode; if(textRef) { @@ -48,14 +57,14 @@ exports.parse = function() { tiddlerNode = { type: "tiddler", attributes: { - tiddler: {type: "string", value: targetTitle} + tiddler: {name: "tiddler", type: "string", value: targetTitle} }, isBlock: true, children: [transcludeNode] }; } if(template) { - transcludeNode.attributes.tiddler = {type: "string", value: template}; + transcludeNode.attributes["$tiddler"] = {name: "$tiddler", type: "string", value: template}; if(textRef) { return [tiddlerNode]; } else { @@ -63,12 +72,12 @@ exports.parse = function() { } } else { if(textRef) { - transcludeNode.attributes.tiddler = {type: "string", value: targetTitle}; + transcludeNode.attributes["$tiddler"] = {name: "$tiddler", type: "string", value: targetTitle}; if(targetField) { - transcludeNode.attributes.field = {type: "string", value: targetField}; + transcludeNode.attributes["$field"] = {name: "$field", type: "string", value: targetField}; } if(targetIndex) { - transcludeNode.attributes.index = {type: "string", value: targetIndex}; + transcludeNode.attributes["$index"] = {name: "$index", type: "string", value: targetIndex}; } return [tiddlerNode]; } else { diff --git a/core/modules/parsers/wikiparser/rules/transcludeinline.js b/core/modules/parsers/wikiparser/rules/transcludeinline.js index dbf39bfb6..3ce9dc78e 100644 --- a/core/modules/parsers/wikiparser/rules/transcludeinline.js +++ b/core/modules/parsers/wikiparser/rules/transcludeinline.js @@ -23,7 +23,7 @@ exports.types = {inline: true}; exports.init = function(parser) { this.parser = parser; // Regexp to match - this.matchRegExp = /\{\{([^\{\}\|]*)(?:\|\|([^\|\{\}]+))?\}\}/mg; + this.matchRegExp = /\{\{([^\{\}\|]*)(?:\|\|([^\|\{\}]+))?(?:\|([^\{\}]+))?\}\}/mg; }; exports.parse = function() { @@ -31,12 +31,21 @@ exports.parse = function() { this.parser.pos = this.matchRegExp.lastIndex; // Get the match details var template = $tw.utils.trim(this.match[2]), - textRef = $tw.utils.trim(this.match[1]); + textRef = $tw.utils.trim(this.match[1]), + params = this.match[3] ? this.match[3].split("|") : []; // Prepare the transclude widget var transcludeNode = { type: "transclude", attributes: {} }; + $tw.utils.each(params,function(paramValue,index) { + var name = "" + index; + transcludeNode.attributes[name] = { + name: name, + type: "string", + value: paramValue + } + }); // Prepare the tiddler widget var tr, targetTitle, targetField, targetIndex, tiddlerNode; if(textRef) { @@ -47,13 +56,13 @@ exports.parse = function() { tiddlerNode = { type: "tiddler", attributes: { - tiddler: {type: "string", value: targetTitle} + tiddler: {name: "tiddler", type: "string", value: targetTitle} }, children: [transcludeNode] }; } if(template) { - transcludeNode.attributes.tiddler = {type: "string", value: template}; + transcludeNode.attributes["$tiddler"] = {name: "$tiddler", type: "string", value: template}; if(textRef) { return [tiddlerNode]; } else { @@ -61,12 +70,12 @@ exports.parse = function() { } } else { if(textRef) { - transcludeNode.attributes.tiddler = {type: "string", value: targetTitle}; + transcludeNode.attributes["$tiddler"] = {name: "$tiddler", type: "string", value: targetTitle}; if(targetField) { - transcludeNode.attributes.field = {type: "string", value: targetField}; + transcludeNode.attributes["$field"] = {name: "$field", type: "string", value: targetField}; } if(targetIndex) { - transcludeNode.attributes.index = {type: "string", value: targetIndex}; + transcludeNode.attributes["$index"] = {name: "$index", type: "string", value: targetIndex}; } return [tiddlerNode]; } else { diff --git a/core/modules/parsers/wikiparser/wikiparser.js b/core/modules/parsers/wikiparser/wikiparser.js index 4c7419030..bb457b205 100644 --- a/core/modules/parsers/wikiparser/wikiparser.js +++ b/core/modules/parsers/wikiparser/wikiparser.js @@ -32,6 +32,7 @@ options: see below: parseAsInline: true to parse text as inline instead of block wiki: reference to wiki to use _canonical_uri: optional URI of content if text is missing or empty + configTrimWhiteSpace: true to trim whitespace */ var WikiParser = function(type,text,options) { this.wiki = options.wiki; @@ -46,7 +47,7 @@ var WikiParser = function(type,text,options) { this.source = text || ""; this.sourceLength = this.source.length; // Flag for ignoring whitespace - this.configTrimWhiteSpace = false; + this.configTrimWhiteSpace = options.configTrimWhiteSpace !== undefined ? options.configTrimWhiteSpace : false; // Parser mode this.parseAsInline = options.parseAsInline; // Set current parse position diff --git a/core/modules/widgets/fill.js b/core/modules/widgets/fill.js new file mode 100644 index 000000000..de88c95af --- /dev/null +++ b/core/modules/widgets/fill.js @@ -0,0 +1,30 @@ +/*\ +title: $:/core/modules/widgets/fill.js +type: application/javascript +module-type: widget + +Sub-widget used by the transclude widget for specifying values for slots within transcluded content. It doesn't do anything by itself because the transclude widget only ever deals with the parse tree nodes, and doesn't instantiate the widget itself + +\*/ +(function(){ + +/*jslint node: true, browser: true */ +/*global $tw: false */ +"use strict"; + +var Widget = require("$:/core/modules/widgets/widget.js").widget; + +var FillWidget = function(parseTreeNode,options) { + // Initialise + this.initialise(parseTreeNode,options); +}; + +/* +Inherit from the base widget class +*/ +FillWidget.prototype = new Widget(); + +exports.fill = FillWidget; + +})(); + \ No newline at end of file diff --git a/core/modules/widgets/importvariables.js b/core/modules/widgets/importvariables.js index a73abfdcf..aafc8ba8b 100644 --- a/core/modules/widgets/importvariables.js +++ b/core/modules/widgets/importvariables.js @@ -52,38 +52,44 @@ ImportVariablesWidget.prototype.execute = function(tiddlerList) { var parser = widgetPointer.wiki.parseTiddler(title,{parseAsInline:true}); if(parser) { var parseTreeNode = parser.tree[0]; - while(parseTreeNode && parseTreeNode.type === "set") { + while(parseTreeNode && ["setvariable","set","parameters"].indexOf(parseTreeNode.type) !== -1) { var node = { type: "set", attributes: parseTreeNode.attributes, params: parseTreeNode.params, - isMacroDefinition: parseTreeNode.isMacroDefinition + isMacroDefinition: parseTreeNode.isMacroDefinition, + isFunctionDefinition: parseTreeNode.isFunctionDefinition, + isProcedureDefinition: parseTreeNode.isProcedureDefinition, + isWidgetDefinition: parseTreeNode.isWidgetDefinition, + configTrimWhiteSpace: parseTreeNode.configTrimWhiteSpace }; - if (parseTreeNode.isMacroDefinition) { - // Macro definitions can be folded into - // current widget instead of adding - // another link to the chain. - var widget = widgetPointer.makeChildWidget(node); - widget.computeAttributes(); - widget.execute(); - // We SHALLOW copy over all variables - // in widget. We can't use - // $tw.utils.assign, because that copies - // up the prototype chain, which we - // don't want. - $tw.utils.each(Object.keys(widget.variables), function(key) { - widgetPointer.variables[key] = widget.variables[key]; - }); - } else { - widgetPointer.children = [widgetPointer.makeChildWidget(node)]; - // No more regenerating children for - // this widget. If it needs to refresh, - // it'll do so along with the the whole - // importvariable tree. - if (widgetPointer != this) { - widgetPointer.makeChildWidgets = function(){}; + if(parseTreeNode.type === "set" || parseTreeNode.type === "setvariable") { + if(parseTreeNode.isMacroDefinition || parseTreeNode.isProcedureDefinition || parseTreeNode.isWidgetDefinition || parseTreeNode.isFunctionDefinition) { + // Macro definitions can be folded into + // current widget instead of adding + // another link to the chain. + var widget = widgetPointer.makeChildWidget(node); + widget.computeAttributes(); + widget.execute(); + // We SHALLOW copy over all variables + // in widget. We can't use + // $tw.utils.assign, because that copies + // up the prototype chain, which we + // don't want. + $tw.utils.each(Object.keys(widget.variables), function(key) { + widgetPointer.variables[key] = widget.variables[key]; + }); + } else { + widgetPointer.children = [widgetPointer.makeChildWidget(node)]; + // No more regenerating children for + // this widget. If it needs to refresh, + // it'll do so along with the the whole + // importvariable tree. + if (widgetPointer != this) { + widgetPointer.makeChildWidgets = function(){}; + } + widgetPointer = widgetPointer.children[0]; } - widgetPointer = widgetPointer.children[0]; } parseTreeNode = parseTreeNode.children && parseTreeNode.children[0]; } diff --git a/core/modules/widgets/macrocall.js b/core/modules/widgets/macrocall.js index 9de2e5d67..e49eadfe0 100644 --- a/core/modules/widgets/macrocall.js +++ b/core/modules/widgets/macrocall.js @@ -37,7 +37,7 @@ MacroCallWidget.prototype.render = function(parent,nextSibling) { Compute the internal state of the widget */ MacroCallWidget.prototype.execute = function() { - // Get the parse type if specified + this.macroName = this.parseTreeNode.name || this.getAttribute("$name"), this.parseType = this.getAttribute("$type","text/vnd.tiddlywiki"); this.renderOutput = this.getAttribute("$output","text/html"); // Merge together the parameters specified in the parse tree with the specified attributes @@ -47,49 +47,26 @@ MacroCallWidget.prototype.execute = function() { params.push({name: name, value: attribute}); } }); - // Get the macro value - var macroName = this.parseTreeNode.name || this.getAttribute("$name"), - variableInfo = this.getVariableInfo(macroName,{params: params}), - text = variableInfo.text, - parseTreeNodes; - // Are we rendering to HTML? - if(this.renderOutput === "text/html") { - // If so we'll return the parsed macro - // Check if we've already cached parsing this macro - var mode = this.parseTreeNode.isBlock ? "blockParser" : "inlineParser", - parser; - if(variableInfo.srcVariable && variableInfo.srcVariable[mode]) { - parser = variableInfo.srcVariable[mode]; - } else { - parser = this.wiki.parseText(this.parseType,text, - {parseAsInline: !this.parseTreeNode.isBlock}); - if(variableInfo.isCacheable && variableInfo.srcVariable) { - variableInfo.srcVariable[mode] = parser; - } - } - var parseTreeNodes = parser ? parser.tree : []; - // Wrap the parse tree in a vars widget assigning the parameters to variables named "__paramname__" - var attributes = {}; - $tw.utils.each(variableInfo.params,function(param) { - var name = "__" + param.name + "__"; - attributes[name] = { - name: name, - type: "string", - value: param.value - }; - }); + // Make a transclude widget + var positionalName = 0, parseTreeNodes = [{ - type: "vars", - attributes: attributes, - children: parseTreeNodes + type: "transclude", + isBlock: this.parseTreeNode.isBlock }]; - } else if(this.renderOutput === "text/raw") { - parseTreeNodes = [{type: "text", text: text}]; - } else { - // Otherwise, we'll render the text - var plainText = this.wiki.renderText("text/plain",this.parseType,text,{parentWidget: this}); - parseTreeNodes = [{type: "text", text: plainText}]; - } + $tw.utils.addAttributeToParseTreeNode(parseTreeNodes[0],"$variable",this.macroName); + $tw.utils.addAttributeToParseTreeNode(parseTreeNodes[0],"$type",this.parseType); + $tw.utils.addAttributeToParseTreeNode(parseTreeNodes[0],"$output",this.renderOutput); + $tw.utils.each(params,function(param) { + var name = param.name; + if(name) { + if(name.charAt(0) === "$") { + name = "$" + name; + } + $tw.utils.addAttributeToParseTreeNode(parseTreeNodes[0],name,param.value); + } else { + $tw.utils.addAttributeToParseTreeNode(parseTreeNodes[0],(positionalName++) + "",param.value); + } + }); // Construct the child widgets this.makeChildWidgets(parseTreeNodes); }; diff --git a/core/modules/widgets/parameters.js b/core/modules/widgets/parameters.js new file mode 100644 index 000000000..69194cb9e --- /dev/null +++ b/core/modules/widgets/parameters.js @@ -0,0 +1,96 @@ +/*\ +title: $:/core/modules/widgets/parameters.js +type: application/javascript +module-type: widget + +Widget for definition of transclusion parameters + +\*/ +(function(){ + +/*jslint node: true, browser: true */ +/*global $tw: false */ +"use strict"; + +var Widget = require("$:/core/modules/widgets/widget.js").widget, + TranscludeWidget = require("$:/core/modules/widgets/transclude.js").transclude; + +var ParametersWidget = function(parseTreeNode,options) { + // Initialise + this.initialise(parseTreeNode,options); +}; + +/* +Inherit from the base widget class +*/ +ParametersWidget.prototype = new Widget(); + +/* +Render this widget into the DOM +*/ +ParametersWidget.prototype.render = function(parent,nextSibling) { + // Call the constructor + Widget.call(this); + this.parentDomNode = parent; + this.computeAttributes(); + this.execute(); + this.renderChildren(parent,nextSibling); +}; + +/* +Compute the internal state of the widget +*/ +ParametersWidget.prototype.execute = function() { + var self = this; + this.parametersDepth = Math.max(parseInt(this.getAttribute("$depth","1"),10) || 1,1); + // Find the parent transclusions + var pointer = this.parentWidget, + depth = this.parametersDepth; + while(pointer) { + if(pointer instanceof TranscludeWidget) { + depth--; + if(depth <= 0) { + break; + } + } + pointer = pointer.parentWidget; + } + // Process each parameter + if(pointer instanceof TranscludeWidget) { + // Get the value for each defined parameter + $tw.utils.each($tw.utils.getOrderedAttributesFromParseTreeNode(self.parseTreeNode),function(attr,index) { + var name = attr.name; + // If the attribute name starts with $$ then reduce to a single dollar + if(name.substr(0,2) === "$$") { + name = name.substr(1); + } + var value = pointer.getTransclusionParameter(name,index,self.getAttribute(attr.name,"")); + self.setVariable(name,value); + }); + // Assign any metaparameters + $tw.utils.each(pointer.getTransclusionMetaParameters(),function(getValue,name) { + var variableName = self.getAttribute("$" + name); + if(variableName) { + self.setVariable(variableName,getValue(name)); + } + }); + } + // Construct the child widgets + this.makeChildWidgets(); +}; + +/* +Refresh the widget by ensuring our attributes are up to date +*/ +ParametersWidget.prototype.refresh = function(changedTiddlers) { + var changedAttributes = this.computeAttributes(); + if(Object.keys(changedAttributes).length) { + this.refreshSelf(); + return true; + } + return this.refreshChildren(changedTiddlers); +}; + +exports.parameters = ParametersWidget; + +})(); diff --git a/core/modules/widgets/setvariable.js b/core/modules/widgets/setvariable.js index cc97067c7..f8e98f390 100755 --- a/core/modules/widgets/setvariable.js +++ b/core/modules/widgets/setvariable.js @@ -48,7 +48,17 @@ SetWidget.prototype.execute = function() { this.setValue = this.getAttribute("value"); this.setEmptyValue = this.getAttribute("emptyValue"); // Set context variable - this.setVariable(this.setName,this.getValue(),this.parseTreeNode.params,!!this.parseTreeNode.isMacroDefinition); + if(this.parseTreeNode.isMacroDefinition) { + this.setVariable(this.setName,this.getValue(),this.parseTreeNode.params,true); + } else if(this.parseTreeNode.isFunctionDefinition) { + this.setVariable(this.setName,this.getValue(),this.parseTreeNode.params,undefined,{isFunctionDefinition: true}); + } else if(this.parseTreeNode.isProcedureDefinition) { + this.setVariable(this.setName,this.getValue(),this.parseTreeNode.params,undefined,{isProcedureDefinition: true, configTrimWhiteSpace: this.parseTreeNode.configTrimWhiteSpace}); + } else if(this.parseTreeNode.isWidgetDefinition) { + this.setVariable(this.setName,this.getValue(),this.parseTreeNode.params,undefined,{isWidgetDefinition: true, configTrimWhiteSpace: this.parseTreeNode.configTrimWhiteSpace}); + } else { + this.setVariable(this.setName,this.getValue()); + } // Construct the child widgets this.makeChildWidgets(); }; diff --git a/core/modules/widgets/slot.js b/core/modules/widgets/slot.js new file mode 100644 index 000000000..6fc402ac2 --- /dev/null +++ b/core/modules/widgets/slot.js @@ -0,0 +1,82 @@ +/*\ +title: $:/core/modules/widgets/slot.js +type: application/javascript +module-type: widget + +Widget for definition of slots within transcluded content. The values provided by the translusion are passed to the slot. + +\*/ +(function(){ + +/*jslint node: true, browser: true */ +/*global $tw: false */ +"use strict"; + +var Widget = require("$:/core/modules/widgets/widget.js").widget, + TranscludeWidget = require("$:/core/modules/widgets/transclude.js").transclude; + +var SlotWidget = function(parseTreeNode,options) { + // Initialise + this.initialise(parseTreeNode,options); +}; + +/* +Inherit from the base widget class +*/ +SlotWidget.prototype = new Widget(); + +/* +Render this widget into the DOM +*/ +SlotWidget.prototype.render = function(parent,nextSibling) { + // Call the constructor + Widget.call(this); + this.parentDomNode = parent; + this.computeAttributes(); + this.execute(); + this.renderChildren(parent,nextSibling); +}; + +/* +Compute the internal state of the widget +*/ +SlotWidget.prototype.execute = function() { + var self = this; + this.slotName = this.getAttribute("$name"); + this.slotDepth = parseInt(this.getAttribute("$depth","1"),10) || 1; + // Find the parent transclusions + var pointer = this.parentWidget, + depth = this.slotDepth; + while(pointer) { + if(pointer instanceof TranscludeWidget) { + depth--; + if(depth <= 0) { + break; + } + } + pointer = pointer.parentWidget; + } + var parseTreeNodes = [{type: "text", attributes: {text: {type: "string", value: "Missing slot reference!"}}}]; + if(pointer instanceof TranscludeWidget) { + // Get the parse tree nodes comprising the slot contents + parseTreeNodes = pointer.getTransclusionSlotFill(this.slotName,this.parseTreeNode.children); + } + // Construct the child widgets + this.makeChildWidgets(parseTreeNodes); +}; + +/* +Refresh the widget by ensuring our attributes are up to date +*/ +SlotWidget.prototype.refresh = function(changedTiddlers) { + var changedAttributes = this.computeAttributes(); + if(changedAttributes["$name"] || changedAttributes["$depth"]) { + this.refreshSelf(); + return true; + } + return this.refreshChildren(changedTiddlers); +}; + +exports.slot = SlotWidget; + +})(); diff --git a/core/modules/widgets/transclude.js b/core/modules/widgets/transclude.js index d7862d2eb..1831f6b6d 100755 --- a/core/modules/widgets/transclude.js +++ b/core/modules/widgets/transclude.js @@ -37,46 +37,347 @@ TranscludeWidget.prototype.render = function(parent,nextSibling) { Compute the internal state of the widget */ TranscludeWidget.prototype.execute = function() { - // Get our parameters - this.transcludeTitle = this.getAttribute("tiddler",this.getVariable("currentTiddler")); - this.transcludeSubTiddler = this.getAttribute("subtiddler"); - this.transcludeField = this.getAttribute("field"); - this.transcludeIndex = this.getAttribute("index"); - this.transcludeMode = this.getAttribute("mode"); - this.recursionMarker = this.getAttribute("recursionMarker","yes"); - // Parse the text reference + // Get our attributes, string parameters, and slot values into properties of the widget object + this.collectAttributes(); + this.collectStringParameters(); + this.collectSlotFillParameters(); + // Get the parse tree nodes that we are transcluding + var target = this.getTransclusionTarget(), + parseTreeNodes = target.parseTreeNodes; + this.sourceText = target.text; + this.sourceType = target.type; + this.parseAsInline = target.parseAsInline; + // Process the transclusion according to the output type + switch(this.transcludeOutput || "text/html") { + case "text/html": + // No further processing required + break; + case "text/raw": + // Just return the raw text + parseTreeNodes = [{type: "text", text: this.sourceText}]; + break; + default: + // text/plain + var plainText = this.wiki.renderText("text/plain",this.sourceType,this.sourceText,{parentWidget: this}); + parseTreeNodes = [{type: "text", text: plainText}]; + break; + } + // Set the legacy transclusion context variables only if we're not transcluding a variable + if(!this.transcludeVariable) { + var recursionMarker = this.makeRecursionMarker(); + this.setVariable("transclusion",recursionMarker); + } + // Construct the child widgets + this.makeChildWidgets(parseTreeNodes); +}; + +/* +Collect the attributes we need, in the process determining whether we're being used in legacy mode +*/ +TranscludeWidget.prototype.collectAttributes = function() { + var self = this; + // Detect legacy mode + this.legacyMode = true; + $tw.utils.each(this.attributes,function(value,name) { + if(name.charAt(0) === "$") { + self.legacyMode = false; + } + }); + // Get the attributes for the appropriate mode + if(this.legacyMode) { + this.transcludeTitle = this.getAttribute("tiddler",this.getVariable("currentTiddler")); + this.transcludeSubTiddler = this.getAttribute("subtiddler"); + this.transcludeField = this.getAttribute("field"); + this.transcludeIndex = this.getAttribute("index"); + this.transcludeMode = this.getAttribute("mode"); + this.recursionMarker = this.getAttribute("recursionMarker","yes"); + } else { + this.transcludeVariable = this.getAttribute("$variable"); + this.transcludeType = this.getAttribute("$type"); + this.transcludeOutput = this.getAttribute("$output","text/html"); + this.transcludeTitle = this.getAttribute("$tiddler",this.getVariable("currentTiddler")); + this.transcludeSubTiddler = this.getAttribute("$subtiddler"); + this.transcludeField = this.getAttribute("$field"); + this.transcludeIndex = this.getAttribute("$index"); + this.transcludeMode = this.getAttribute("$mode"); + this.recursionMarker = this.getAttribute("$recursionMarker","yes"); + } +}; + +/* +Collect string parameters +*/ +TranscludeWidget.prototype.collectStringParameters = function() { + var self = this; + this.stringParametersByName = Object.create(null); + if(!this.legacyMode) { + $tw.utils.each(this.attributes,function(value,name) { + if(name.charAt(0) === "$") { + if(name.charAt(1) === "$") { + // Attributes starting $$ represent parameters starting with a single $ + name = name.slice(1); + } else { + // Attributes starting with a single $ are reserved for the widget + return; + } + } + self.stringParametersByName[name] = value; + }); + } +}; + +/* +Collect slot value parameters +*/ +TranscludeWidget.prototype.collectSlotFillParameters = function() { + var self = this; + this.slotFillParseTrees = Object.create(null); + if(this.legacyMode) { + this.slotFillParseTrees["ts-missing"] = this.parseTreeNode.children; + } else { + this.slotFillParseTrees["ts-raw"] = this.parseTreeNode.children; + var noFillWidgetsFound = true, + searchParseTreeNodes = function(nodes) { + $tw.utils.each(nodes,function(node) { + if(node.type === "fill") { + if(node.attributes["$name"] && node.attributes["$name"].type === "string") { + var slotValueName = node.attributes["$name"].value; + self.slotFillParseTrees[slotValueName] = node.children || []; + } + noFillWidgetsFound = false; + } else { + searchParseTreeNodes(node.children); + } + }); + }; + searchParseTreeNodes(this.parseTreeNode.children); + if(noFillWidgetsFound) { + this.slotFillParseTrees["ts-missing"] = this.parseTreeNode.children; + } + } +}; + +/* +Get transcluded parse tree nodes as an object {parser:,text:,type:} +*/ +TranscludeWidget.prototype.getTransclusionTarget = function() { + var self = this; + // Determine whether we're being used in inline or block mode var parseAsInline = !this.parseTreeNode.isBlock; if(this.transcludeMode === "inline") { parseAsInline = true; } else if(this.transcludeMode === "block") { parseAsInline = false; } - var parser = this.wiki.parseTextReference( + var parser; + // Get the parse tree + if(this.transcludeVariable) { + // Transcluding a variable + var variableInfo = this.getVariableInfo(this.transcludeVariable,{params: this.getOrderedTransclusionParameters()}), + srcVariable = variableInfo && variableInfo.srcVariable; + if(srcVariable) { + if(srcVariable.isFunctionDefinition) { + // Function to return parameters by name or position + var fnGetParam = function(name,index) { + // Parameter names starting with dollar must be escaped to double dollars + if(name.charAt(0) === "$") { + name = "$" + name; + } + // Look for the parameter by name + if(self.hasAttribute(name)) { + return self.getAttribute(name); + // Look for the parameter by index + } else if(self.hasAttribute(index + "")) { + return self.getAttribute(index + ""); + } else { + return undefined; + } + }, + result = this.evaluateVariable(this.transcludeVariable,{params: fnGetParam})[0] || ""; + parser = { + tree: [{ + type: "text", + text: result + }], + source: result, + type: "text/vnd.tiddlywiki" + }; + if(parseAsInline) { + parser.tree[0] = { + type: "text", + text: result + }; + } else { + parser.tree[0] = { + type: "element", + tag: "p", + children: [{ + type: "text", + text: result + }] + } + } + } else { + var cacheKey = (parseAsInline ? "inlineParser" : "blockParser") + (this.transcludeType || ""); + if(variableInfo.isCacheable && srcVariable[cacheKey]) { + parser = srcVariable[cacheKey]; + } else { + parser = this.wiki.parseText(this.transcludeType,variableInfo.text || "",{parseAsInline: parseAsInline, configTrimWhiteSpace: srcVariable.configTrimWhiteSpace}); + if(variableInfo.isCacheable) { + srcVariable[cacheKey] = parser; + } + } + } + if(parser) { + // Add parameters widget for procedures and custom widgets + if(srcVariable.isProcedureDefinition || srcVariable.isWidgetDefinition) { + parser = { + tree: [ + { + type: "parameters", + children: parser.tree + } + ], + source: parser.source, + type: parser.type + } + $tw.utils.each(srcVariable.params,function(param) { + var name = param.name; + // Parameter names starting with dollar must be escaped to double dollars + if(name.charAt(0) === "$") { + name = "$" + name; + } + $tw.utils.addAttributeToParseTreeNode(parser.tree[0],name,param["default"]) + }); + } else { + // For macros and ordinary variables, wrap the parse tree in a vars widget assigning the parameters to variables named "__paramname__" + parser = { + tree: [ + { + type: "vars", + children: parser.tree + } + ], + source: parser.source, + type: parser.type + } + $tw.utils.each(variableInfo.params,function(param) { + $tw.utils.addAttributeToParseTreeNode(parser.tree[0],"__" + param.name + "__",param.value) + }); + } + } + } + } else { + // Transcluding a text reference + parser = this.wiki.parseTextReference( this.transcludeTitle, this.transcludeField, this.transcludeIndex, { parseAsInline: parseAsInline, - subTiddler: this.transcludeSubTiddler - }), - parseTreeNodes = parser ? parser.tree : this.parseTreeNode.children; - this.sourceText = parser ? parser.source : null; - this.parserType = parser? parser.type : null; - // Set context variables for recursion detection - var recursionMarker = this.makeRecursionMarker(); - if(this.recursionMarker === "yes") { - this.setVariable("transclusion",recursionMarker); + subTiddler: this.transcludeSubTiddler, + defaultType: this.transcludeType + }); } - // Check for recursion + // Return the parse tree if(parser) { - if(this.parentWidget && this.parentWidget.hasVariable("transclusion",recursionMarker)) { - parseTreeNodes = [{type: "error", attributes: { - "$message": {type: "string", value: $tw.language.getString("Error/RecursiveTransclusion")} - }}]; + return { + parser: parser, + parseTreeNodes: parser.tree, + parseAsInline: parseAsInline, + text: parser.source, + type: parser.type + }; + } else { + // If there's no parse tree then return the missing slot value + return { + parser: null, + parseTreeNodes: (this.slotFillParseTrees["ts-missing"] || []), + parseAsInline: parseAsInline, + text: null, + type: null + }; + } +}; + +/* +Fetch all the string parameters as an ordered array of {name:, value:} where the name is optional +*/ +TranscludeWidget.prototype.getOrderedTransclusionParameters = function() { + var result = []; + // Collect the parameters + for(var name in this.stringParametersByName) { + var value = this.stringParametersByName[name]; + result.push({name: name, value: value}); + } + // Sort numerical parameter names first + result.sort(function(a,b) { + var aIsNumeric = !isNaN(a.name), + bIsNumeric = !isNaN(b.name); + if(aIsNumeric && bIsNumeric) { + return a.name - b.name; + } else if(aIsNumeric) { + return -1; + } else if(bIsNumeric) { + return 1; + } else { + return a.name === b.name ? 0 : (a.name < b.name ? -1 : 1); + } + }); + // Remove names from numerical parameters + $tw.utils.each(result,function(param,index) { + if(!isNaN(param.name)) { + delete param.name; + } + }); + return result; +}; + +/* +Fetch the value of a parameter +*/ +TranscludeWidget.prototype.getTransclusionParameter = function(name,index,defaultValue) { + if(name in this.stringParametersByName) { + return this.stringParametersByName[name]; + } else { + var name = "" + index; + if(name in this.stringParametersByName) { + return this.stringParametersByName[name]; } } - // Construct the child widgets - this.makeChildWidgets(parseTreeNodes); + return defaultValue; +}; + +/* +Get one of the special parameters to be provided by the parameters widget +*/ +TranscludeWidget.prototype.getTransclusionMetaParameters = function() { + var self = this; + return { + "parseMode": function() { + return self.parseAsInline ? "inline" : "block"; + }, + "parseTreeNodes": function() { + return JSON.stringify(self.parseTreeNode.children || []); + }, + "slotFillParseTreeNodes": function() { + return JSON.stringify(self.slotFillParseTrees); + }, + "params": function() { + return JSON.stringify(self.stringParametersByName); + } + }; +}; + +/* +Fetch the value of a slot +*/ +TranscludeWidget.prototype.getTransclusionSlotFill = function(name,defaultParseTreeNodes) { + if(name && this.slotFillParseTrees[name] && this.slotFillParseTrees[name].length > 0) { + return this.slotFillParseTrees[name]; + } else { + return defaultParseTreeNodes || []; + } }; /* @@ -99,6 +400,7 @@ TranscludeWidget.prototype.makeRecursionMarker = function() { }; TranscludeWidget.prototype.parserNeedsRefresh = function() { + // Doesn't need to consider transcluded variables because a parent variable can't change once a widget has been created var parserInfo = this.wiki.getTextReferenceParserInfo(this.transcludeTitle,this.transcludeField,this.transcludeIndex,{subTiddler:this.transcludeSubTiddler}); return (this.sourceText === undefined || parserInfo.sourceText !== this.sourceText || parserInfo.parserType !== this.parserType) }; @@ -108,7 +410,7 @@ Selectively refreshes the widget if needed. Returns true if the widget or any of */ TranscludeWidget.prototype.refresh = function(changedTiddlers) { var changedAttributes = this.computeAttributes(); - if(($tw.utils.count(changedAttributes) > 0) || (changedTiddlers[this.transcludeTitle] && this.parserNeedsRefresh())) { + if(($tw.utils.count(changedAttributes) > 0) || (!this.transcludeVariable && changedTiddlers[this.transcludeTitle] && this.parserNeedsRefresh())) { this.refreshSelf(); return true; } else { diff --git a/core/modules/widgets/widget.js b/core/modules/widgets/widget.js index 60f55e8bb..741914fdc 100755 --- a/core/modules/widgets/widget.js +++ b/core/modules/widgets/widget.js @@ -41,10 +41,7 @@ Widget.prototype.initialise = function(parseTreeNode,options) { this.parseTreeNode = parseTreeNode; this.wiki = options.wiki; this.parentWidget = options.parentWidget; - this.variables = Object.create(null); - if(this.parentWidget) { - Object.setPrototypeOf(this.variables,this.parentWidget.variables); - } + this.variables = Object.create(this.parentWidget ? this.parentWidget.variables : null); this.document = options.document; this.attributes = {}; this.children = []; @@ -92,9 +89,22 @@ name: name of the variable value: value of the variable params: array of {name:, default:} for each parameter isMacroDefinition: true if the variable is set via a \define macro pragma (and hence should have variable substitution performed) +options includes: + isProcedureDefinition: true if the variable is set via a \procedure pragma (and hence should not have variable substitution performed) + isFunctionDefinition: true if the variable is set via a \function pragma (and hence should not have variable substitution performed) + isWidgetDefinition: true if the variable is set via a \widget pragma (and hence should not have variable substitution performed) */ -Widget.prototype.setVariable = function(name,value,params,isMacroDefinition) { - this.variables[name] = {value: value, params: params, isMacroDefinition: !!isMacroDefinition}; +Widget.prototype.setVariable = function(name,value,params,isMacroDefinition,options) { + options = options || {}; + this.variables[name] = { + value: value, + params: params, + isMacroDefinition: !!isMacroDefinition, + isFunctionDefinition: !!options.isFunctionDefinition, + isProcedureDefinition: !!options.isProcedureDefinition, + isWidgetDefinition: !!options.isWidgetDefinition, + configTrimWhiteSpace: !!options.configTrimWhiteSpace + }; }; /* @@ -104,6 +114,7 @@ options: see below Options include params: array of {name:, value:} for each parameter defaultValue: default value if the variable is not defined +allowSelfAssigned: if true, includes the current widget in the context chain instead of just the parent Returns an object with the following fields: @@ -112,21 +123,27 @@ text: text of variable, with parameters properly substituted */ Widget.prototype.getVariableInfo = function(name,options) { options = options || {}; - var actualParams = options.params || [], - parentWidget = this.parentWidget; + var self = this, + actualParams = options.params || [], + variable; + if(options.allowSelfAssigned) { + variable = this.variables[name]; + } else { + variable = this.parentWidget && this.parentWidget.variables[name]; + } // Check for the variable defined in the parent widget (or an ancestor in the prototype chain) - if(parentWidget && name in parentWidget.variables) { - var variable = parentWidget.variables[name], - originalValue = variable.value, + if(variable) { + var originalValue = variable.value, value = originalValue, - params = this.resolveVariableParameters(variable.params,actualParams); - // Substitute any parameters specified in the definition - $tw.utils.each(params,function(param) { - value = $tw.utils.replaceString(value,new RegExp("\\$" + $tw.utils.escapeRegExp(param.name) + "\\$","mg"),param.value); - }); - // Only substitute variable references if this variable was defined with the \define pragma + params = []; + // Only substitute parameter and variable references if this variable was defined with the \define pragma if(variable.isMacroDefinition) { - value = this.substituteVariableReferences(value,options); + params = self.resolveVariableParameters(variable.params,actualParams); + // Substitute any parameters specified in the definition + $tw.utils.each(params,function(param) { + value = $tw.utils.replaceString(value,new RegExp("\\$" + $tw.utils.escapeRegExp(param.name) + "\\$","mg"),param.value); + }); + value = self.substituteVariableReferences(value,options); } return { text: value, @@ -136,8 +153,13 @@ Widget.prototype.getVariableInfo = function(name,options) { }; } // If the variable doesn't exist in the parent widget then look for a macro module + var text = this.evaluateMacroModule(name,actualParams); + if(text === undefined) { + text = options.defaultValue; + } return { - text: this.evaluateMacroModule(name,actualParams,options.defaultValue) + text: text, + srcVariable: {} }; }; @@ -148,6 +170,11 @@ Widget.prototype.getVariable = function(name,options) { return this.getVariableInfo(name,options).text; }; +/* +Maps actual parameters onto formal parameters, returning an array of {name:,value:} objects +formalParams - Array of {name:,default:} (default value is optional) +actualParams - Array of string values or {name:,value:} (name is optional) +*/ Widget.prototype.resolveVariableParameters = function(formalParams,actualParams) { formalParams = formalParams || []; actualParams = actualParams || []; @@ -160,7 +187,7 @@ Widget.prototype.resolveVariableParameters = function(formalParams,actualParams) paramInfo = formalParams[p]; paramValue = undefined; for(var m=0; m 0) { + var letVariableWidget = { + type: "let", attributes: { - name: {type: "string", value: name}, - value: {type: "string", value: value} }, children: [] }; - currWidgetNode.children = [setVariableWidget]; - currWidgetNode = setVariableWidget; - }); + $tw.utils.each(options.variables,function(value,name) { + $tw.utils.addAttributeToParseTreeNode(letVariableWidget,name,"" + value); + }); + currWidgetNode.children = [letVariableWidget]; + currWidgetNode = letVariableWidget; + } // Add in the supplied parse tree nodes currWidgetNode.children = parser ? parser.tree : []; // Create the widget diff --git a/core/ui/Components/VisibleTransclude.tid b/core/ui/Components/VisibleTransclude.tid new file mode 100644 index 000000000..cbc981abe --- /dev/null +++ b/core/ui/Components/VisibleTransclude.tid @@ -0,0 +1,48 @@ +title: $:/core/ui/VisibleTransclude + + +\widget $transclude() + +<$parameters tiddler="" $$tiddler="" mode="" $$mode="" $parseMode="@parseMode" $params="@params"> + + <$let + mode={{{ [[$mode]is[variable]then<$mode>!is[blank]] :else[[mode]is[variable]then!is[blank]] :else[<@parseMode>] }}} + outputTag={{{ [match[inline]then[span]else[div]] }}} + outputColour={{{ [match[inline]then[green]else[red]] }}} + > + + <$genesis $type=<> style="color:white;padding:4px;" style.background=<>> + <$genesis $type=<> style="display: inline-block;"> +
+ + <$list filter="[<@params>jsonindexes[]]" emptyMessage="(none)"> +
+ <$text text=<>/><$text text=": "/><$text text={{{ [<@params>jsonget] }}}/> +
+ +
+ + <$genesis $type=<> style="background:white;color:black;padding:4px;"> + + <$list filter="[<@params>jsonindexes[]] :filter[prefix[$]] +[limit[1]]" variable="ignore" emptyMessage=""" + + <$genesis $type="$transclude" $remappable="no" $names="[<@params>jsonindexes[]]" $values="[<@params>jsonindexes[]] :map[<@params>jsonget]" recursionMarker="no" mode=<>> + + <$slot $name="ts-raw" $depth="2"/> + + """> + + <$genesis $type="$transclude" $remappable="no" $names="[<@params>jsonindexes[]]" $values="[<@params>jsonindexes[]] :map[<@params>jsonget]" $$recursionMarker="no" $$mode=<>> + + <$slot $name="ts-raw" $depth="2"/> + + + + + + +\end diff --git a/core/wiki/macros/tabs.tid b/core/wiki/macros/tabs.tid index f439e541d..bc8a0255f 100644 --- a/core/wiki/macros/tabs.tid +++ b/core/wiki/macros/tabs.tid @@ -60,4 +60,4 @@ code-body: yes -\end +\end \ No newline at end of file diff --git a/editions/prerelease/tiddlers/Release 5.2.8.tid b/editions/prerelease/tiddlers/Release 5.2.8.tid deleted file mode 100644 index 18ca202b5..000000000 --- a/editions/prerelease/tiddlers/Release 5.2.8.tid +++ /dev/null @@ -1,60 +0,0 @@ -caption: 5.2.8 -created: 20230326093239710 -modified: 20230326093239710 -tags: ReleaseNotes -title: Release 5.2.8 -type: text/vnd.tiddlywiki - -//[[See GitHub for detailed change history of this release|https://github.com/Jermolene/TiddlyWiki5/compare/v5.2.7...master]]// - -! Major Improvements - -! Translation Improvements - -Improvements to the following translations: - -* - -! Plugin Improvements - -* - -! Accessibility Improvements - -* - -! Usability Improvements - -* - -! Widget Improvements - -* - -! Filter improvements - -* - -! Hackability Improvements - -* - -! Bug Fixes - -* - -! Node.js Improvements - -* - -! Performance Improvements - -* - -! Acknowledgements - -[[@Jermolene|https://github.com/Jermolene]] would like to thank the contributors to this release who have generously given their time to help improve TiddlyWiki: - -<<.contributors """ - -""">> \ No newline at end of file diff --git a/editions/prerelease/tiddlers/Release 5.3.0.tid b/editions/prerelease/tiddlers/Release 5.3.0.tid new file mode 100644 index 000000000..63a57cd4d --- /dev/null +++ b/editions/prerelease/tiddlers/Release 5.3.0.tid @@ -0,0 +1,83 @@ +caption: 5.3.0 +created: 20230419103154368 +modified: 20230419103154368 +tags: ReleaseNotes +title: Release 5.3.0 +type: text/vnd.tiddlywiki + +//[[See GitHub for detailed change history of this release|https://github.com/Jermolene/TiddlyWiki5/compare/master...parameterised-transclusions]]// + +! About v5.3.0 + +This pre-release introduces a number of significant improvements and new features related to some of TiddlyWiki's most fundamental components: macros, widgets, operators and transclusion. + +! Introduction to v5.3.0 + +The motivation of these changes is to fix one of ~TiddlyWiki 5's early design flaws: the reliance on macros using textual substitution as the primary way to modularise and reuse wikitext and filters. + +Experience has shown that while macros are a good match for a small number of tasks, they are brittle and error prone for many common operations. See [[Macro Pitfalls]] for a discussion of the problems that accompany this approach. Over the years we have introduced mitigations for the worst problems but these have come at a cost of increased complexity. + +The changes in this release provide powerful new ways to achieve common tasks, and unlock completely new capabilities that were previously impossible in wikitext. + +* [[Procedures]], which are essentially what macros should have been; they work in exactly the same way except that parameters are exposed as simple variables (without the double underscores) and no textual substitution takes place +* [[Custom Widgets]], allowing the creation of widgets in wikitext, and the redefinition of built-in widgets +* [[Functions]], a new way to encapsulate filter expressions with named parameters, including the ability to make custom filter operators +* Parameterised [[Transclusions|Transclusion]], allowing strings and wikitext trees to be passed to transclusions + +The approach taken by this release is to add new functionality by extending and augmenting the system without disturbing existing functionality. All of these changes are thus intended to be backwards compatible. While they represent a new field of opportunities for wikitext authors, it is possible for authors to ignore all these new features and continue to use ~TiddlyWiki 5 in the way that they have always done. + +These changes lay the groundwork for macros and related features to be deprecated (which is the point at which users are advised not to use old features, and instead given clear pointers to the equivalent modern functionality). + +The new transclusion architecture is not by itself sufficient to enable us to fully deprecate macros yet. To handle the remaining use cases we propose a new backtick quoted attribute format that allows for the substitution of variable values. See https://github.com/Jermolene/TiddlyWiki5/issues/6663 for details. + +! Plugin Improvements + +* + +! Translation improvement + +Improvements to the following translations: + +* + +! Accessibility Improvements + +* + +! Usability Improvements + +* + +! Widget Improvements + +* + +! Filter improvements + +* + +! Hackability Improvements + +* + +! Bug Fixes + +* + +! Developer Improvements + +* + +! Node.js Improvements + +* + +! Performance Improvements + +* +! Acknowledgements + +[[@Jermolene|https://github.com/Jermolene]] would like to thank the contributors to this release who have generously given their time to help improve TiddlyWiki: + +<<.contributors """ +""">> diff --git a/editions/test/tiddlers/tests/data/custom-operators/NestedParameterised.tid b/editions/test/tiddlers/tests/data/custom-operators/NestedParameterised.tid new file mode 100644 index 000000000..3e4d610d0 --- /dev/null +++ b/editions/test/tiddlers/tests/data/custom-operators/NestedParameterised.tid @@ -0,0 +1,24 @@ +title: CustomOperators/NestedParameterised +description: Nested parameterised custom operator usage +type: text/vnd.tiddlywiki-multiple +tags: [[$:/tags/wiki-test-spec]] + +title: Output + +\whitespace trim +\function .dividebysomething(first:ignored,factor:0.5) +[divide[2]multiply] +\end + +\function .multiplebysomething(first:ignored,factor:2) +[multiply[2].dividebysomething[],] +\end + +<$text text={{{ [[123].multiplebysomething[]] }}}/> +- +<$text text={{{ [[123].multiplebysomething[x],[4]] }}}/> + ++ +title: ExpectedResult + +

246-492

\ No newline at end of file diff --git a/editions/test/tiddlers/tests/data/custom-operators/Parameterised.tid b/editions/test/tiddlers/tests/data/custom-operators/Parameterised.tid new file mode 100644 index 000000000..2f8337b0f --- /dev/null +++ b/editions/test/tiddlers/tests/data/custom-operators/Parameterised.tid @@ -0,0 +1,24 @@ +title: CustomOperators/Parameterised +description: Parameterised custom operator usage +type: text/vnd.tiddlywiki-multiple +tags: [[$:/tags/wiki-test-spec]] + +title: Output + +\whitespace trim +\function .multiplybysomething(first:ignored,factor:2) +[multiply[2]multiply] +\end + +<$text text={{{ [[123].multiplybysomething[]] }}}/> +- +<$text text={{{ [[123].multiplybysomething[x],[4]] }}}/> +| +<$text text={{{ [[123]function[.multiplybysomething]] }}}/> +- +<$text text={{{ [[123]function[.multiplybysomething],[x],[4]] }}}/> + ++ +title: ExpectedResult + +

492-984|492-984

\ No newline at end of file diff --git a/editions/test/tiddlers/tests/data/custom-operators/Simple.tid b/editions/test/tiddlers/tests/data/custom-operators/Simple.tid new file mode 100644 index 000000000..089701295 --- /dev/null +++ b/editions/test/tiddlers/tests/data/custom-operators/Simple.tid @@ -0,0 +1,21 @@ +title: CustomOperators/Simple +description: Simple custom operator usage +type: text/vnd.tiddlywiki-multiple +tags: [[$:/tags/wiki-test-spec]] + +title: Output + +\whitespace trim + +\function .multiplybytwo() +[multiply[2]] +\end + +<$text text={{{ [[123].multiplybytwo[]] }}}/> +| +<$text text={{{ [[123]function[.multiplybytwo]] }}}/> + ++ +title: ExpectedResult + +

246|246

\ No newline at end of file diff --git a/editions/test/tiddlers/tests/data/functions/FunctionAttributes.tid b/editions/test/tiddlers/tests/data/functions/FunctionAttributes.tid new file mode 100644 index 000000000..2deb49bdc --- /dev/null +++ b/editions/test/tiddlers/tests/data/functions/FunctionAttributes.tid @@ -0,0 +1,24 @@ +title: Functions/FunctionAttributes +description: Attributes specified as function invocations +type: text/vnd.tiddlywiki-multiple +tags: [[$:/tags/wiki-test-spec]] + +title: Output + +\whitespace trim +\function .dividebysomething(factor:0.5) +[divide] +\end + +\function multiplebysomething(first:ignored,factor:2) +[multiply[2].dividebysomething[0.25]] +\end + +<$text text=<>/> +| +<$text text=<>/> + ++ +title: ExpectedResult + +

16|32

\ No newline at end of file diff --git a/editions/test/tiddlers/tests/data/functions/FunctionOperator.tid b/editions/test/tiddlers/tests/data/functions/FunctionOperator.tid new file mode 100644 index 000000000..e2a0038dc --- /dev/null +++ b/editions/test/tiddlers/tests/data/functions/FunctionOperator.tid @@ -0,0 +1,24 @@ +title: Functions/FunctionOperator +description: Calling a function via the function operator +type: text/vnd.tiddlywiki-multiple +tags: [[$:/tags/wiki-test-spec]] + +title: Output + +\whitespace trim +\function .dividebysomething(factor:0.5) +[divide] +\end + +\function multiplebysomething(first:ignored,factor:2) +[multiplymultiply[2].dividebysomething[0.25]] +\end + +<$text text={{{ [[4]function[multiplebysomething]] }}}/> +| +<$text text={{{ [[6]function[multiplebysomething],[ignored],[4]] }}}/> + ++ +title: ExpectedResult + +

64|192

\ No newline at end of file diff --git a/editions/test/tiddlers/tests/data/functions/MissingFunction.tid b/editions/test/tiddlers/tests/data/functions/MissingFunction.tid new file mode 100644 index 000000000..25498e452 --- /dev/null +++ b/editions/test/tiddlers/tests/data/functions/MissingFunction.tid @@ -0,0 +1,15 @@ +title: Functions/MissingFunction +description: Calling a missing function via the function operator +type: text/vnd.tiddlywiki-multiple +tags: [[$:/tags/wiki-test-spec]] + +title: Output + +\whitespace trim + +<$text text={{{ [[23]function[missing]] }}}/> + ++ +title: ExpectedResult + +23 \ No newline at end of file diff --git a/editions/test/tiddlers/tests/data/functions/RunawayRecursiveFunctions.tid b/editions/test/tiddlers/tests/data/functions/RunawayRecursiveFunctions.tid new file mode 100644 index 000000000..81be22f16 --- /dev/null +++ b/editions/test/tiddlers/tests/data/functions/RunawayRecursiveFunctions.tid @@ -0,0 +1,18 @@ +title: Functions/RunawayRecursiveFunctions +description: Runaway recursive functions +type: text/vnd.tiddlywiki-multiple +tags: [[$:/tags/wiki-test-spec]] + +title: Output + +\whitespace trim +\function .buffalo(p) +[.buffalo

] +\end + +<$text text=<<.buffalo 8>>/> + ++ +title: ExpectedResult + +/**-- Excessive filter recursion --**/ \ No newline at end of file diff --git a/editions/test/tiddlers/tests/data/functions/UndefinedParameters.tid b/editions/test/tiddlers/tests/data/functions/UndefinedParameters.tid new file mode 100644 index 000000000..8a2b0a91a --- /dev/null +++ b/editions/test/tiddlers/tests/data/functions/UndefinedParameters.tid @@ -0,0 +1,22 @@ +title: Functions/UndefinedParameters +description: Undefined function parameters +type: text/vnd.tiddlywiki-multiple +tags: [[$:/tags/wiki-test-spec]] + +title: Output + +\function greet(who) +[[hello ]addsuffix] +\end + +<$text text={{{[function[greet],[world]]}}}/> + +<> + +<$text text={{{[function[greet]]}}}/> + +<> ++ +title: ExpectedResult + +hello world

hello world

hello

hello

\ No newline at end of file diff --git a/editions/test/tiddlers/tests/data/functions/WikifiedFunctions.tid b/editions/test/tiddlers/tests/data/functions/WikifiedFunctions.tid new file mode 100644 index 000000000..733fbdaef --- /dev/null +++ b/editions/test/tiddlers/tests/data/functions/WikifiedFunctions.tid @@ -0,0 +1,36 @@ +title: Functions/WikifiedFunctions +description: Wikified functions +type: text/vnd.tiddlywiki-multiple +tags: [[$:/tags/wiki-test-spec]] + +title: Output + +\whitespace trim +\function fn-buffalo(param) +[addsuffix[ with a ''buffalo'']] +\end + +\procedure proc-buffalo(param) +<> with a ''buffalo'' +\end + +\define macro-buffalo(param) +$param$ with a ''buffalo'' +\end + +<> + +<> + +<> + +<$transclude $variable="fn-buffalo" param="Going to lunch" $output="text/plain"/> + +<$transclude $variable="proc-buffalo" param="Going to breakfast" $output="text/plain"/> + +<$transclude $variable="macro-buffalo" param="Going to dinner" $output="text/plain"/> + ++ +title: ExpectedResult + +

Going to lunch with a ''buffalo''

Going to breakfastwith abuffalo

Going to dinner with a buffalo

Going to lunch with a buffalo with a buffaloGoing to dinner with a buffalo \ No newline at end of file diff --git a/editions/test/tiddlers/tests/data/genesis-widget/RedefineLet.tid b/editions/test/tiddlers/tests/data/genesis-widget/RedefineLet.tid new file mode 100644 index 000000000..f6834998d --- /dev/null +++ b/editions/test/tiddlers/tests/data/genesis-widget/RedefineLet.tid @@ -0,0 +1,31 @@ +title: Genesis/RedefineLet +description: Using the genesis widget to override the let widget +type: text/vnd.tiddlywiki-multiple +tags: [[$:/tags/wiki-test-spec]] + +title: Output + +\whitespace trim +\widget $let() +\whitespace trim +<$parameters $params="@params"> +<$setmultiplevariables $names="[<@params>jsonindexes[]]" $values="[<@params>jsonindexes[]] :map[<@params>jsongetaddprefix[--]addsuffix[--]]"> +<$slot $name="ts-raw"/> + + +\end +<$let + one="Elephant" + $two="Kangaroo" + $$three="Giraffe" +> +(<$text text=<>/>) +(<$text text=<<$two>>/>) +(<$text text=<<$$three>>/>) + ++ +title: ExpectedResult + +

(--Elephant--) +(--Kangaroo--) +(--Giraffe--)

\ No newline at end of file diff --git a/editions/test/tiddlers/tests/data/procedures/Nested.tid b/editions/test/tiddlers/tests/data/procedures/Nested.tid new file mode 100644 index 000000000..f63c634af --- /dev/null +++ b/editions/test/tiddlers/tests/data/procedures/Nested.tid @@ -0,0 +1,20 @@ +title: Procedures/Nested +description: Nested Procedures +type: text/vnd.tiddlywiki-multiple +tags: [[$:/tags/wiki-test-spec]] + +title: Output + +\whitespace trim +\procedure alpha(x) +\procedure beta(y) +<$text text=<>/> +\end beta +<$transclude $variable="beta" y={{{ [addprefix] }}}/> +\end alpha + +<> ++ +title: ExpectedResult + +

ElephantElephant

\ No newline at end of file diff --git a/editions/test/tiddlers/tests/data/transclude/CustomWidget-ActionWidget.tid b/editions/test/tiddlers/tests/data/transclude/CustomWidget-ActionWidget.tid new file mode 100644 index 000000000..0be77a9a3 --- /dev/null +++ b/editions/test/tiddlers/tests/data/transclude/CustomWidget-ActionWidget.tid @@ -0,0 +1,27 @@ +title: Transclude/CustomWidget/ActionWidget +description: Custom widget definition +type: text/vnd.tiddlywiki-multiple +tags: [[$:/tags/wiki-test-spec]] + +title: Output + +\whitespace trim +<$transclude $tiddler='Result'> + ++ +title: Actions + +\whitespace trim + +\widget $$action-mywidget(one:'Jaguar') +\whitespace trim +<$action-setfield $tiddler="Result" $field="text" $value=<>/> +\end + +<$$action-mywidget one="Dingo"> + Crocodile + ++ +title: ExpectedResult + +

Dingo

\ No newline at end of file diff --git a/editions/test/tiddlers/tests/data/transclude/CustomWidget-Fail.tid b/editions/test/tiddlers/tests/data/transclude/CustomWidget-Fail.tid new file mode 100644 index 000000000..3d0759013 --- /dev/null +++ b/editions/test/tiddlers/tests/data/transclude/CustomWidget-Fail.tid @@ -0,0 +1,26 @@ +title: Transclude/CustomWidget/Fail +description: Custom widget failed definition +type: text/vnd.tiddlywiki-multiple +tags: [[$:/tags/wiki-test-spec]] + +title: Output + +\whitespace trim + +\widget $non-existent-widget(one:'Jaguar') +\whitespace trim +<$text text=<>/> +<$slot $name="ts-raw"> + Whale + +\end +<$non-existent-widget one="Dingo"> + Crocodile + +<$non-existent-widget one="BumbleBee"> + Squirrel + ++ +title: ExpectedResult + +

Undefined widget 'non-existent-widget'Undefined widget 'non-existent-widget'

\ No newline at end of file diff --git a/editions/test/tiddlers/tests/data/transclude/CustomWidget-Override-Codeblock.tid b/editions/test/tiddlers/tests/data/transclude/CustomWidget-Override-Codeblock.tid new file mode 100644 index 000000000..c4730622b --- /dev/null +++ b/editions/test/tiddlers/tests/data/transclude/CustomWidget-Override-Codeblock.tid @@ -0,0 +1,29 @@ +title: CustomWidget-Override-Codeblock +description: Usage of genesis widget with attributes starting with dollar signs +type: text/vnd.tiddlywiki-multiple +tags: [[$:/tags/wiki-test-spec]] + +title: Output + +\whitespace trim +\import Definition +<$codeblock code="Kangaroo"/> +<$codeblock code={{Subject}}/> +<$let test="Tiger"> +<$codeblock code=<>/> + ++ +title: Definition + +\whitespace trim +\widget $codeblock(code) +<$genesis $type="$codeblock" $remappable="no" code={{{ [addprefix[£]addsuffix[@]] }}}/> +\end ++ +title: Subject + +Python ++ +title: ExpectedResult + +

£Kangaroo@
£Python@
£Tiger@

\ No newline at end of file diff --git a/editions/test/tiddlers/tests/data/transclude/CustomWidget-OverrideTransclude.tid b/editions/test/tiddlers/tests/data/transclude/CustomWidget-OverrideTransclude.tid new file mode 100644 index 000000000..c57e4a9a1 --- /dev/null +++ b/editions/test/tiddlers/tests/data/transclude/CustomWidget-OverrideTransclude.tid @@ -0,0 +1,33 @@ +title: Transclude/CustomWidget/OverrideTransclude +description: Custom widget definition attempting to override transclude +type: text/vnd.tiddlywiki-multiple +tags: [[$:/tags/wiki-test-spec]] + +title: Output + +\whitespace trim +<$transclude $tiddler='TiddlerOne' one='Ferret'> + ++ +title: TiddlerZero + +Antelope ++ +title: TiddlerOne + +\whitespace trim + +\widget $transclude(one:'Jaguar') +\whitespace trim + <$text text=<>/> + <$slot $name="body"> + Whale + +\end +<$genesis $type="$transclude" $remappable="no" $$tiddler="TiddlerZero"> + Crocodile + ++ +title: ExpectedResult + +

Antelope

\ No newline at end of file diff --git a/editions/test/tiddlers/tests/data/transclude/CustomWidget-Simple.tid b/editions/test/tiddlers/tests/data/transclude/CustomWidget-Simple.tid new file mode 100644 index 000000000..15d0c8d9e --- /dev/null +++ b/editions/test/tiddlers/tests/data/transclude/CustomWidget-Simple.tid @@ -0,0 +1,33 @@ +title: Transclude/CustomWidget/Simple +description: Custom widget definition +type: text/vnd.tiddlywiki-multiple +tags: [[$:/tags/wiki-test-spec]] + +title: Output + +\whitespace trim +<$transclude $tiddler='TiddlerOne' one='Ferret'> + ++ +title: TiddlerOne + +\whitespace trim + +\widget $$mywidget(one:'Jaguar') +\whitespace trim +<$text text=<>/> +<$slot $name="ts-raw"> + Whale + +\end +<$$mywidget one="Dingo"> + Crocodile + +<$$mywidget one="BumbleBee"> + Squirrel + +<$$mywidget/> ++ +title: ExpectedResult + +

DingoCrocodileBumbleBeeSquirrelJaguarWhale

\ No newline at end of file diff --git a/editions/test/tiddlers/tests/data/transclude/CustomWidget-Slotted-Empty.tid b/editions/test/tiddlers/tests/data/transclude/CustomWidget-Slotted-Empty.tid new file mode 100644 index 000000000..efd1e7041 --- /dev/null +++ b/editions/test/tiddlers/tests/data/transclude/CustomWidget-Slotted-Empty.tid @@ -0,0 +1,20 @@ +title: CustomWidget/Slotted/Empty +description: Custom widget with empty slotted values +type: text/vnd.tiddlywiki-multiple +tags: [[$:/tags/wiki-test-spec]] + +title: Output + +\whitespace trim +\widget $$mywidget() +<$slot $name=ts-raw>the body is empty +\end + +#<$$mywidget/> +#<$$mywidget> +#<$$mywidget>the body is not empty + ++ +title: ExpectedResult + +
  1. the body is empty
  2. the body is empty
  3. the body is not empty
\ No newline at end of file diff --git a/editions/test/tiddlers/tests/data/transclude/CustomWidget-Slotted.tid b/editions/test/tiddlers/tests/data/transclude/CustomWidget-Slotted.tid new file mode 100644 index 000000000..c10e84127 --- /dev/null +++ b/editions/test/tiddlers/tests/data/transclude/CustomWidget-Slotted.tid @@ -0,0 +1,27 @@ +title: Transclude/CustomWidget/Slotted +description: Custom widget definition +type: text/vnd.tiddlywiki-multiple +tags: [[$:/tags/wiki-test-spec]] + +title: Output + +\whitespace trim +\widget $$mywidget(one:'Jaguar') +\whitespace trim +<$text text=<>/> +<$slot $name="ts-stuff"> + Whale + +\end +<$$mywidget one="Dingo"> + <$fill $name="ts-stuff"> + Crocodile + + +<$$mywidget one="BumbleBee"> + Squirrel + ++ +title: ExpectedResult + +

DingoCrocodileBumbleBeeWhale

\ No newline at end of file diff --git a/editions/test/tiddlers/tests/data/transclude/CustomWidget-TextWidgetOverride.tid b/editions/test/tiddlers/tests/data/transclude/CustomWidget-TextWidgetOverride.tid new file mode 100644 index 000000000..d0a3cc82c --- /dev/null +++ b/editions/test/tiddlers/tests/data/transclude/CustomWidget-TextWidgetOverride.tid @@ -0,0 +1,27 @@ +title: Transclude/CustomWidget/TextWidgetOverride +description: Custom widget definition redefining the text widget +type: text/vnd.tiddlywiki-multiple +tags: [[$:/tags/wiki-test-spec]] + +title: Output + +\whitespace trim +<$transclude $tiddler='TiddlerOne'> + ++ +title: TiddlerOne + +\whitespace trim + +\widget $text(text:'Jaguar') +\whitespace trim +<$genesis $type="$text" $remappable="no" text={{{ [addprefix[≤]addsuffix[≥]] }}}/> +\end + +<$text text="Dingo"/> + +Crocodile ++ +title: ExpectedResult + +

≤Dingo≥≤Jaguar≥

\ No newline at end of file diff --git a/editions/test/tiddlers/tests/data/transclude/CustomWidget-TextWidgetOverrideWithSlot.tid b/editions/test/tiddlers/tests/data/transclude/CustomWidget-TextWidgetOverrideWithSlot.tid new file mode 100644 index 000000000..c84c5ae9a --- /dev/null +++ b/editions/test/tiddlers/tests/data/transclude/CustomWidget-TextWidgetOverrideWithSlot.tid @@ -0,0 +1,31 @@ +title: Transclude/CustomWidget/TextWidgetOverrideWithSlot +description: Custom widget definition redefining the text widget +type: text/vnd.tiddlywiki-multiple +tags: [[$:/tags/wiki-test-spec]] + +title: Output + +\whitespace trim +<$transclude $tiddler='TiddlerOne'> + ++ +title: TiddlerOne + +\whitespace trim + +\widget $text(text:'Jaguar') +\whitespace trim +<$genesis $type="$text" $remappable="no" text=<>/> +<$set name="$text" value=""> + <$slot $name="ts-raw"> + Whale + + +\end +<$text text="Dingo"> + Crocodile + ++ +title: ExpectedResult + +

DingoCrocodile

\ No newline at end of file diff --git a/editions/test/tiddlers/tests/data/transclude/CustomWidget-Unoverride-Codeblock.tid b/editions/test/tiddlers/tests/data/transclude/CustomWidget-Unoverride-Codeblock.tid new file mode 100644 index 000000000..c6a834205 --- /dev/null +++ b/editions/test/tiddlers/tests/data/transclude/CustomWidget-Unoverride-Codeblock.tid @@ -0,0 +1,31 @@ +title: CustomWidget-Unoverride-Codeblock +description: Usage of genesis widget with attributes starting with dollar signs, and unoverriding a core widget +type: text/vnd.tiddlywiki-multiple +tags: [[$:/tags/wiki-test-spec]] + +title: Output + +\whitespace trim +\import Definition +<$let $codeblock=""> +<$codeblock code="Kangaroo"/> +<$codeblock code={{Subject}}/> +<$let test="Tiger"> +<$codeblock code=<>/> + + ++ +title: Definition + +\whitespace trim +\widget $codeblock(code) +<$genesis $type="codeblock" $remappable="no" code={{{ [addprefix[£]addsuffix[@]] }}}/> +\end ++ +title: Subject + +Python ++ +title: ExpectedResult + +

Kangaroo
Python
Tiger

\ No newline at end of file diff --git a/editions/test/tiddlers/tests/data/transclude/CustomWidget-VariableAttribute.tid b/editions/test/tiddlers/tests/data/transclude/CustomWidget-VariableAttribute.tid new file mode 100644 index 000000000..8ef700b41 --- /dev/null +++ b/editions/test/tiddlers/tests/data/transclude/CustomWidget-VariableAttribute.tid @@ -0,0 +1,29 @@ +title: Transclude/CustomWidget/VariableAttribute +description: Custom widget definition using an attribute called $variable +type: text/vnd.tiddlywiki-multiple +tags: [[$:/tags/wiki-test-spec]] + +title: Output + +\whitespace trim +<$transclude $tiddler='TiddlerOne' one='Ferret'> + ++ +title: TiddlerOne + +\whitespace trim + +\widget $$mywidget($variable:'Jaguar') +\whitespace trim +<$text text=<<$variable>>/> +<$slot $name="ts-raw"> + Whale + +\end +<$$mywidget $variable="Dingo"> + Crocodile + ++ +title: ExpectedResult + +

DingoCrocodile

\ No newline at end of file diff --git a/editions/test/tiddlers/tests/data/transclude/JavaScript-Macro.tid b/editions/test/tiddlers/tests/data/transclude/JavaScript-Macro.tid new file mode 100644 index 000000000..216a89dc8 --- /dev/null +++ b/editions/test/tiddlers/tests/data/transclude/JavaScript-Macro.tid @@ -0,0 +1,17 @@ +title: Transclude/Macro/JavaScript +description: Transcluding a javascript macro +type: text/vnd.tiddlywiki-multiple +tags: [[$:/tags/wiki-test-spec]] + +title: Output + +\whitespace trim + +<> + +<$macrocall $name="makedatauri" text="Wildebeest" type="text/plain"/> + ++ +title: ExpectedResult + +

data:text/plain,Wildebeest

data:text/plain,Wildebeest

\ No newline at end of file diff --git a/editions/test/tiddlers/tests/data/transclude/Macro-Plain.tid b/editions/test/tiddlers/tests/data/transclude/Macro-Plain.tid new file mode 100644 index 000000000..410144153 --- /dev/null +++ b/editions/test/tiddlers/tests/data/transclude/Macro-Plain.tid @@ -0,0 +1,17 @@ +title: Transclude/Macro/Plain +description: Transcluding a macro as plain text +type: text/vnd.tiddlywiki-multiple +tags: [[$:/tags/wiki-test-spec]] + +title: Output + +\whitespace trim +<$let currentTab="Jeremy"> +<$macrocall $name="currentTab" $type="text/plain" $output="text/plain"/> +| +<$transclude $variable="currentTab" $type="text/plain" $output="text/plain"/> + ++ +title: ExpectedResult + +

Jeremy|Jeremy

\ No newline at end of file diff --git a/editions/test/tiddlers/tests/data/transclude/Macro-Simple.tid b/editions/test/tiddlers/tests/data/transclude/Macro-Simple.tid new file mode 100644 index 000000000..71db5efe4 --- /dev/null +++ b/editions/test/tiddlers/tests/data/transclude/Macro-Simple.tid @@ -0,0 +1,26 @@ +title: Transclude/Macro/Simple +description: Transcluding a macro +type: text/vnd.tiddlywiki-multiple +tags: [[$:/tags/wiki-test-spec]] + +title: Output + +\whitespace trim +\define mamacro(one:"red",two:"green") +It is $one$ and $two$ or <<__one__>> and <<__two__>>. +\end + +<$macrocall $name="mamacro"/> + +<$transclude $variable="mamacro"/> + +<$transclude $variable="mamacro" one="orange"/> + +<$transclude $variable="mamacro" 0="pink"/> + +<$transclude $variable="mamacro" one="purple" 1="pink"/> + ++ +title: ExpectedResult + +

It is red and green or red and green.

It is red and green or red and green.

It is orange and green or orange and green.

It is pink and green or pink and green.

It is purple and pink or purple and pink.

\ No newline at end of file diff --git a/editions/test/tiddlers/tests/data/transclude/MissingTarget.tid b/editions/test/tiddlers/tests/data/transclude/MissingTarget.tid new file mode 100644 index 000000000..8bdc86eaa --- /dev/null +++ b/editions/test/tiddlers/tests/data/transclude/MissingTarget.tid @@ -0,0 +1,48 @@ +title: Transclude/MissingTarget +description: Transcluding a missing target +type: text/vnd.tiddlywiki-multiple +tags: [[$:/tags/wiki-test-spec]] + +title: Output + +\whitespace trim +<$transclude $tiddler='TiddlerOne' one='Ferret'> + <$parameters one='Ferret'> + Badger + <$text text=<>/> + + +<$transclude $tiddler='TiddlerOne' one='Ferret'> + <$fill $name="ts-missing"> + <$parameters one='Ferret'> + Badger + <$text text=<>/> + + + +<$transclude $tiddler='MissingTiddler' one='Ferret'> + <$parameters one='Ferret'> + Badger + <$text text=<>/> + + +<$transclude $tiddler='MissingTiddler' one='Ferret'> + <$fill $name="ts-missing"> + <$parameters one='Ferret'> + Badger + <$text text=<>/> + + + ++ +title: TiddlerOne + +\whitespace trim +<$parameters one='Kangaroo'> + Piranha + <$text text=<>/> + ++ +title: ExpectedResult + +

PiranhaFerretPiranhaFerretBadgerFerretBadgerFerret

\ No newline at end of file diff --git a/editions/test/tiddlers/tests/data/transclude/Parameterised-Depth.tid b/editions/test/tiddlers/tests/data/transclude/Parameterised-Depth.tid new file mode 100644 index 000000000..064e225c8 --- /dev/null +++ b/editions/test/tiddlers/tests/data/transclude/Parameterised-Depth.tid @@ -0,0 +1,34 @@ +title: Transclude/Parameterised/Depth +description: Parameterised transclusion using the $depth attribute +type: text/vnd.tiddlywiki-multiple +tags: [[$:/tags/wiki-test-spec]] + +title: Output + +\whitespace trim +<$transclude $tiddler='TiddlerOne' one='Ferret'/> +| +<$transclude $tiddler='TiddlerOne'/> +| +<$transclude $tiddler='TiddlerOne' one='Ferret' $$two="Osprey"/> +| +<$transclude $tiddler='TiddlerOne' $$two="Falcon"/> ++ +title: TiddlerOne + +\whitespace trim +{{TiddlerTwo}} ++ +title: TiddlerTwo + +\whitespace trim +<$parameters one='Jaguar' $$two='Piranha' $depth="2"> + <$text text=<>/>:<$text text=<<$two>>/> + +<$parameters one='Leopard' $$two='Coelacanth'> + (<$text text=<>/>|<$text text=<<$two>>/>) + ++ +title: ExpectedResult + +

Ferret:Piranha(Leopard|Coelacanth)|Jaguar:Piranha(Leopard|Coelacanth)|Ferret:Osprey(Leopard|Coelacanth)|Jaguar:Falcon(Leopard|Coelacanth)

\ No newline at end of file diff --git a/editions/test/tiddlers/tests/data/transclude/Parameterised-Mode.tid b/editions/test/tiddlers/tests/data/transclude/Parameterised-Mode.tid new file mode 100644 index 000000000..04f5bbb04 --- /dev/null +++ b/editions/test/tiddlers/tests/data/transclude/Parameterised-Mode.tid @@ -0,0 +1,29 @@ +title: Transclude/Parameterised/Mode +description: Parameterised transclusion using the $parseMode attribute +type: text/vnd.tiddlywiki-multiple +tags: [[$:/tags/wiki-test-spec]] + +title: Output + +\whitespace trim + +<$transclude $tiddler='TiddlerOne' one='Ferret'> + +This is a block + + + +<$transclude $tiddler='TiddlerOne'> +This is inline + ++ +title: TiddlerOne + +\whitespace trim +<$parameters $parseMode="@parseMode"> + <$text text=<<@parseMode>>/> + ++ +title: ExpectedResult + +

block

inline

\ No newline at end of file diff --git a/editions/test/tiddlers/tests/data/transclude/Parameterised-Name-Values.tid b/editions/test/tiddlers/tests/data/transclude/Parameterised-Name-Values.tid new file mode 100644 index 000000000..9d62a7897 --- /dev/null +++ b/editions/test/tiddlers/tests/data/transclude/Parameterised-Name-Values.tid @@ -0,0 +1,34 @@ +title: Transclude/Parameterised/Name/Values +description: Parameterised transclusion accessing parameters as name/value pairs +type: text/vnd.tiddlywiki-multiple +tags: [[$:/tags/wiki-test-spec]] + +title: Output + +\whitespace trim +<$transclude $tiddler="TiddlerOne" 0="" 1="" 2=""/> + +{{TiddlerOne}} +{{TiddlerOne|Ferret}} +{{TiddlerOne|Butterfly|Moth}} +{{TiddlerOne|Beetle|Scorpion|Snake}} +{{TiddlerOne||TiddlerTwo|Beetle|Scorpion|Snake}} ++ +title: TiddlerOne + +\whitespace trim +<$parameters zero='Jaguar' $$one='Lizard' two='Mole' $params="@params"> +<$list filter="[<@params>jsonindexes[]]"> +{<$text text=<>/>: <$text text={{{ [<@params>jsonget] }}}/>} + + ++ +title: TiddlerTwo + +\whitespace trim +\parameters(zero:'Mouse',$one:'Horse',two:'Owl') +(<$transclude $tiddler=<> zero=<> $$one=<<$one>> two=<>/>) ++ +title: ExpectedResult + +

{0:}{1:}{2:}

{0:Ferret}

{0:Butterfly}{1:Moth}

{0:Beetle}{1:Scorpion}{2:Snake}

({$one:Scorpion}{two:Snake}{zero:Beetle})

\ No newline at end of file diff --git a/editions/test/tiddlers/tests/data/transclude/Parameterised-ParseTreeNodes.tid b/editions/test/tiddlers/tests/data/transclude/Parameterised-ParseTreeNodes.tid new file mode 100644 index 000000000..916e2abfb --- /dev/null +++ b/editions/test/tiddlers/tests/data/transclude/Parameterised-ParseTreeNodes.tid @@ -0,0 +1,29 @@ +title: Transclude/Parameterised/ParseTreeNodes +description: Parameterised transclusion using the $parseTreeNodes attribute +type: text/vnd.tiddlywiki-multiple +tags: [[$:/tags/wiki-test-spec]] + +title: Output + +\whitespace trim + +<$transclude $tiddler='TiddlerOne' one='Ferret'> + +This is a block + + + +<$transclude $tiddler='TiddlerOne'> +This is inline + ++ +title: TiddlerOne + +\whitespace trim +<$parameters $parseTreeNodes="@parseTreeNodes"> + <$text text=<<@parseTreeNodes>>/> + ++ +title: ExpectedResult + +

[{"type":"element","tag":"p","children":[{"type":"text","text":"This is a block","start":68,"end":83}],"start":68,"end":83}]

[{"type":"text","text":"This is inline","start":136,"end":152}]

\ No newline at end of file diff --git a/editions/test/tiddlers/tests/data/transclude/Parameterised-Positional-Shortcut-Parameters.tid b/editions/test/tiddlers/tests/data/transclude/Parameterised-Positional-Shortcut-Parameters.tid new file mode 100644 index 000000000..abf444adb --- /dev/null +++ b/editions/test/tiddlers/tests/data/transclude/Parameterised-Positional-Shortcut-Parameters.tid @@ -0,0 +1,29 @@ +title: Transclude/Parameterised/Positional/Shortcut/Parameters +description: Positional parameterised transclusion using shortcut syntax and parameters pragma +type: text/vnd.tiddlywiki-multiple +tags: [[$:/tags/wiki-test-spec]] + +title: Output + +\whitespace trim +{{TiddlerOne}} +{{TiddlerOne|Ferret}} +{{TiddlerOne|Butterfly|Moth}} +{{TiddlerOne|Beetle|Scorpion|Snake}} +{{TiddlerOne||TiddlerTwo|Beetle|Scorpion|Snake}} ++ +title: TiddlerOne + +\whitespace trim +\parameters(zero:Jaguar,one:'Lizard',two:'Mole') +[{<$text text=<>/>}{<$text text=<>/>}{<$text text=<>/>}] ++ +title: TiddlerTwo + +\whitespace trim +\parameters(zero:'Mouse',one:Horse,two:'Owl') +(<$transclude $tiddler=<> zero=<> one=<> two=<>/>) ++ +title: ExpectedResult + +

[{Jaguar}{Lizard}{Mole}]

[{Ferret}{Lizard}{Mole}]

[{Butterfly}{Moth}{Mole}]

[{Beetle}{Scorpion}{Snake}]

([{Beetle}{Scorpion}{Snake}])

\ No newline at end of file diff --git a/editions/test/tiddlers/tests/data/transclude/Parameterised-Positional-Shortcut.tid b/editions/test/tiddlers/tests/data/transclude/Parameterised-Positional-Shortcut.tid new file mode 100644 index 000000000..7792e6c66 --- /dev/null +++ b/editions/test/tiddlers/tests/data/transclude/Parameterised-Positional-Shortcut.tid @@ -0,0 +1,29 @@ +title: Transclude/Parameterised/Positional/Shortcut +description: Positional parameterised transclusion using shortcut syntax +type: text/vnd.tiddlywiki-multiple +tags: [[$:/tags/wiki-test-spec]] + +title: Output + +\whitespace trim +{{TiddlerOne}} +{{TiddlerOne|Ferret}} +{{TiddlerOne|Butterfly|Moth}} +{{TiddlerOne|Beetle|Scorpion|Snake}} +{{TiddlerOne||TiddlerTwo|Beetle|Scorpion|Snake}} ++ +title: TiddlerOne + +\whitespace trim +<$parameters zero='Jaguar' one='Lizard' two='Mole'>[{<$text text=<>/>}{<$text text=<>/>}{<$text text=<>/>}] ++ +title: TiddlerTwo + +\whitespace trim +<$parameters zero='Mouse' one='Horse' two='Owl'> +(<$transclude $tiddler=<> zero=<> one=<> two=<>/>) + ++ +title: ExpectedResult + +

[{Jaguar}{Lizard}{Mole}]

[{Ferret}{Lizard}{Mole}]

[{Butterfly}{Moth}{Mole}]

[{Beetle}{Scorpion}{Snake}]

([{Beetle}{Scorpion}{Snake}])

\ No newline at end of file diff --git a/editions/test/tiddlers/tests/data/transclude/Parameterised-Positional-Variables.tid b/editions/test/tiddlers/tests/data/transclude/Parameterised-Positional-Variables.tid new file mode 100644 index 000000000..ad2b7be52 --- /dev/null +++ b/editions/test/tiddlers/tests/data/transclude/Parameterised-Positional-Variables.tid @@ -0,0 +1,30 @@ +title: Transclude/Parameterised/Positional/Variables +description: Positional parameterised transclusion of variables +type: text/vnd.tiddlywiki-multiple +tags: [[$:/tags/wiki-test-spec]] + +title: Output + +\whitespace trim +\function myfunction(alpha:"apple",beta:"banana",gamma:"grenadine") [] +\define mymacro(alpha:"apple",beta:"banana",gamma:"grenadine") $beta$ +\function f(a) [] + +(Functions: +<$text text={{{ [] }}}/> +, +<$text text=<>/> +, +<> +)(Macros: +<$text text={{{ [] }}}/> +, +<$text text=<>/> +, +<> +) + ++ +title: ExpectedResult + +

(Functions:f1,f1,f1)(Macros:banana,banana,banana)

\ No newline at end of file diff --git a/editions/test/tiddlers/tests/data/transclude/Parameterised-Positional.tid b/editions/test/tiddlers/tests/data/transclude/Parameterised-Positional.tid new file mode 100644 index 000000000..d7eb9090e --- /dev/null +++ b/editions/test/tiddlers/tests/data/transclude/Parameterised-Positional.tid @@ -0,0 +1,26 @@ +title: Transclude/Parameterised/Positional +description: Positional parameterised transclusion +type: text/vnd.tiddlywiki-multiple +tags: [[$:/tags/wiki-test-spec]] + +title: Output + +\whitespace trim +<$transclude $tiddler='TiddlerOne' zero='Ferret'/> +<$transclude zero='Ferret' $tiddler='TiddlerOne'/> +<$transclude $tiddler='TiddlerOne' 0='Pigeon'/> +<$transclude 0='Pigeon' $tiddler='TiddlerOne'/> +<$transclude $tiddler='TiddlerOne' zero='Ferret' 0='Pigeon'/> +<$transclude zero='Ferret' 0='Pigeon' $tiddler='TiddlerOne'/> +<$transclude $tiddler='TiddlerOne'/> ++ +title: TiddlerOne + +\whitespace trim +<$parameters zero='Jaguar'> + <$text text=<>/> + ++ +title: ExpectedResult + +

FerretFerretPigeonPigeonFerretFerretJaguar

\ No newline at end of file diff --git a/editions/test/tiddlers/tests/data/transclude/Parameterised-Shortcut-Parameters.tid b/editions/test/tiddlers/tests/data/transclude/Parameterised-Shortcut-Parameters.tid new file mode 100644 index 000000000..375964199 --- /dev/null +++ b/editions/test/tiddlers/tests/data/transclude/Parameterised-Shortcut-Parameters.tid @@ -0,0 +1,20 @@ +title: Transclude/Parameterised/Shortcut/Parameters +description: Simple parameterised transclusion using the parameters pragma +type: text/vnd.tiddlywiki-multiple +tags: [[$:/tags/wiki-test-spec]] + +title: Output + +\whitespace trim +<$transclude $tiddler='TiddlerOne' one='Ferret'/> +<$transclude $tiddler='TiddlerOne'/> ++ +title: TiddlerOne + +\whitespace trim +\parameters(one:'Jaguar') +<$text text=<>/> ++ +title: ExpectedResult + +

FerretJaguar

\ No newline at end of file diff --git a/editions/test/tiddlers/tests/data/transclude/Parameterised-Shortcut.tid b/editions/test/tiddlers/tests/data/transclude/Parameterised-Shortcut.tid new file mode 100644 index 000000000..0499cf2d6 --- /dev/null +++ b/editions/test/tiddlers/tests/data/transclude/Parameterised-Shortcut.tid @@ -0,0 +1,21 @@ +title: Transclude/Parameterised/Shortcut +description: Simple parameterised transclusion +type: text/vnd.tiddlywiki-multiple +tags: [[$:/tags/wiki-test-spec]] + +title: Output + +\whitespace trim +\procedure test(one:'Jaguar') +{<$text text=<>/>} +\end + +<$transclude $variable='test' one='Ferret'/> +<$transclude $variable='test'/> +<> +<> + ++ +title: ExpectedResult + +

{Ferret}{Jaguar}{Rat}{Mouse}

\ No newline at end of file diff --git a/editions/test/tiddlers/tests/data/transclude/Parameterised-Simple.tid b/editions/test/tiddlers/tests/data/transclude/Parameterised-Simple.tid new file mode 100644 index 000000000..0268f9e59 --- /dev/null +++ b/editions/test/tiddlers/tests/data/transclude/Parameterised-Simple.tid @@ -0,0 +1,26 @@ +title: Transclude/Parameterised/Simple +description: Simple parameterised transclusion +type: text/vnd.tiddlywiki-multiple +tags: [[$:/tags/wiki-test-spec]] + +title: Output + +\whitespace trim +<$transclude $tiddler='TiddlerOne' one='Ferret'/> +| +<$transclude $tiddler='TiddlerOne'/> +| +<$transclude $tiddler='TiddlerOne' one='Ferret' $$two="Osprey"/> +| +<$transclude $tiddler='TiddlerOne' $$two="Falcon"/> ++ +title: TiddlerOne + +\whitespace trim +<$parameters one='Jaguar' $$two='Piranha'> + <$text text=<>/>:<$text text=<<$two>>/> + ++ +title: ExpectedResult + +

Ferret:Piranha|Jaguar:Piranha|Ferret:Osprey|Jaguar:Falcon

\ No newline at end of file diff --git a/editions/test/tiddlers/tests/data/transclude/Parameterised-SlotFillParseTreeNodes.tid b/editions/test/tiddlers/tests/data/transclude/Parameterised-SlotFillParseTreeNodes.tid new file mode 100644 index 000000000..679748375 --- /dev/null +++ b/editions/test/tiddlers/tests/data/transclude/Parameterised-SlotFillParseTreeNodes.tid @@ -0,0 +1,29 @@ +title: Transclude/Parameterised/SlotFillParseTreeNodes +description: Parameterised transclusion using the $slotFillParseTreeNodes attribute +type: text/vnd.tiddlywiki-multiple +tags: [[$:/tags/wiki-test-spec]] + +title: Output + +\whitespace trim + +<$transclude $tiddler='TiddlerOne' one='Ferret'> +<$fill $name="one">This is first +<$fill $name="two">But this is second + + +<$transclude $tiddler='TiddlerOne'> +<$fill $name="one">This is first +<$fill $name="two">But this is second + ++ +title: TiddlerOne + +\whitespace trim +<$parameters $slotFillParseTreeNodes="@slotFillParseTreeNodes"> + <$text text={{{ [<@slotFillParseTreeNodes>jsonindexes[]join[,]] }}}/> + ++ +title: ExpectedResult + +

one,ts-raw,two

one,ts-raw

\ No newline at end of file diff --git a/editions/test/tiddlers/tests/data/transclude/Parameterised-Slotted-Missing.tid b/editions/test/tiddlers/tests/data/transclude/Parameterised-Slotted-Missing.tid new file mode 100644 index 000000000..fe399d572 --- /dev/null +++ b/editions/test/tiddlers/tests/data/transclude/Parameterised-Slotted-Missing.tid @@ -0,0 +1,24 @@ +title: Transclude/Parameterised/Slotted/Missing +description: Parameterised transclusion with slotted missing values +type: text/vnd.tiddlywiki-multiple +tags: [[$:/tags/wiki-test-spec]] + +title: Output + +\whitespace trim +<$transclude $tiddler='TiddlerOne' one='Ferret'> + ++ +title: TiddlerOne + +\whitespace trim +<$parameters one='Jaguar'> + <$text text=<>/> + <$slot $name="content"> + Whale + + ++ +title: ExpectedResult + +

FerretWhale

\ No newline at end of file diff --git a/editions/test/tiddlers/tests/data/transclude/Parameterised-Slotted.tid b/editions/test/tiddlers/tests/data/transclude/Parameterised-Slotted.tid new file mode 100644 index 000000000..c795621ef --- /dev/null +++ b/editions/test/tiddlers/tests/data/transclude/Parameterised-Slotted.tid @@ -0,0 +1,27 @@ +title: Transclude/Parameterised/Slotted +description: Parameterised transclusion with slotted values +type: text/vnd.tiddlywiki-multiple +tags: [[$:/tags/wiki-test-spec]] + +title: Output + +\whitespace trim +<$transclude $tiddler='TiddlerOne' one='Ferret'> + <$fill $name="content"> + Hippopotamus + + ++ +title: TiddlerOne + +\whitespace trim +<$parameters one='Jaguar'> + <$text text=<>/> + <$slot $name="content"> + Whale + + ++ +title: ExpectedResult + +

FerretHippopotamus

\ No newline at end of file diff --git a/editions/test/tiddlers/tests/data/transclude/Procedures-Whitespace.tid b/editions/test/tiddlers/tests/data/transclude/Procedures-Whitespace.tid new file mode 100644 index 000000000..d2bded70c --- /dev/null +++ b/editions/test/tiddlers/tests/data/transclude/Procedures-Whitespace.tid @@ -0,0 +1,25 @@ +title: Transclude/Procedures/Whitespace +description: Procedures should inherit whitespace settings from definition site +type: text/vnd.tiddlywiki-multiple +tags: [[$:/tags/wiki-test-spec]] + +title: Output + +\whitespace trim +\procedure testproc() +This is a sentence +\end + +\define testmacro() +This is a sentence +\end +This is a sentence +[<>] +[<>] + ++ +title: ExpectedResult + +

This is a sentence +[This is a sentence] +[This is a sentence ]

\ No newline at end of file diff --git a/editions/test/tiddlers/tests/data/transclude/Typed.tid b/editions/test/tiddlers/tests/data/transclude/Typed.tid new file mode 100644 index 000000000..c99664b59 --- /dev/null +++ b/editions/test/tiddlers/tests/data/transclude/Typed.tid @@ -0,0 +1,38 @@ +title: Transclude/Typed +description: Typed transclusion +type: text/vnd.tiddlywiki-multiple +tags: [[$:/tags/wiki-test-spec]] + +title: Output + +\procedure testproc() +This is ''wikitext'' +\end + +<$transclude $variable="testproc"/> +- +<$transclude $variable="testproc" $type="text/plain"/> + +<$transclude $tiddler="Data" $index="testindex"/> +- +<$transclude $tiddler="Data" $index="testindex" $type="text/plain"/> + +<$transclude $tiddler="Data" $field="custom"/> +- +<$transclude $tiddler="Data" $field="custom" $type="text/plain"/> ++ +title: Data +type: application/x-tiddler-dictionary +custom: This is ''wikitext'' + +testindex: This is ''wikitext'' ++ +title: ExpectedResult + +

This is wikitext +- +

This is ''wikitext''

This is wikitext +- +

This is ''wikitext''

This is wikitext +- +

This is ''wikitext''

\ No newline at end of file diff --git a/editions/test/tiddlers/tests/test-filters.js b/editions/test/tiddlers/tests/test-filters.js index 2a9080de5..e00d0bf8d 100644 --- a/editions/test/tiddlers/tests/test-filters.js +++ b/editions/test/tiddlers/tests/test-filters.js @@ -422,7 +422,7 @@ Tests the filtering mechanism. expect(wiki.filterTiddlers("[[one]tagging[]sort[title]]").join(",")).toBe("Tiddler Three,Tiddler8,TiddlerOne,TiddlerSeventh"); expect(wiki.filterTiddlers("[[one]tagging[]]").join(",")).toBe("Tiddler Three,TiddlerOne,TiddlerSeventh,Tiddler8"); expect(wiki.filterTiddlers("[[two]tagging[]sort[title]]").join(",")).toBe("$:/TiddlerFive,$:/TiddlerTwo,Tiddler Three"); - var fakeWidget = {getVariable: function() {return "one";}}; + var fakeWidget = {wiki: wiki, getVariable: function(name) {return name === "currentTiddler" ? "one": undefined;}}; expect(wiki.filterTiddlers("[all[current]tagging[]]",fakeWidget).join(",")).toBe("Tiddler Three,TiddlerOne,TiddlerSeventh,Tiddler8"); }); @@ -625,7 +625,7 @@ Tests the filtering mechanism. expect(wiki.filterTiddlers("[{!!title}]").join(",")).toBe(""); expect(wiki.filterTiddlers("[prefix{Tiddler8}] +[sort[title]]").join(",")).toBe("Tiddler Three,TiddlerOne"); expect(wiki.filterTiddlers("[modifier{Tiddler8!!test-field}] +[sort[title]]").join(",")).toBe("TiddlerOne"); - var fakeWidget = {wiki: wiki, getVariable: function() {return "Tiddler Three";}}; + var fakeWidget = {wiki: wiki, getVariable: function(name) {return name === "currentTiddler" ? "Tiddler Three": undefined;}}; expect(wiki.filterTiddlers("[modifier{!!modifier}] +[sort[title]]",fakeWidget).join(",")).toBe("$:/TiddlerTwo,a fourth tiddler,one,Tiddler Three"); }); diff --git a/editions/test/tiddlers/tests/test-parsetextreference.js b/editions/test/tiddlers/tests/test-parsetextreference.js index 376ad9ec4..59f885232 100644 --- a/editions/test/tiddlers/tests/test-parsetextreference.js +++ b/editions/test/tiddlers/tests/test-parsetextreference.js @@ -124,7 +124,7 @@ describe("Wiki.parseTextReference tests", function() { // Non-existent subtiddler of a plugin expect(parseAndGetSource("$:/ShadowPlugin","text",null,"MyMissingTiddler")).toEqual(null); // Plain text tiddler - expect(parseAndGetSource("TiddlerNine")).toEqual(undefined); + expect(parseAndGetSource("TiddlerNine")).toEqual("this is plain text"); }); }); diff --git a/editions/test/tiddlers/tests/test-utils.js b/editions/test/tiddlers/tests/test-utils.js index 8b7630a54..d41d5047a 100644 --- a/editions/test/tiddlers/tests/test-utils.js +++ b/editions/test/tiddlers/tests/test-utils.js @@ -188,4 +188,4 @@ describe("Utility tests", function() { }); -})(); +})(); \ No newline at end of file diff --git a/editions/test/tiddlers/tests/test-widget.js b/editions/test/tiddlers/tests/test-widget.js index 2614d6f52..544ed928f 100755 --- a/editions/test/tiddlers/tests/test-widget.js +++ b/editions/test/tiddlers/tests/test-widget.js @@ -143,7 +143,7 @@ describe("Widget module", function() { var wiki = new $tw.Wiki(); // Add a tiddler wiki.addTiddlers([ - {title: "TiddlerOne", text: "<$transclude tiddler='TiddlerTwo'/>\n"}, + {title: "TiddlerOne", text: "<$transclude tiddler='TiddlerTwo'/>"}, {title: "TiddlerTwo", text: "<$transclude tiddler='TiddlerOne'/>"} ]); // Test parse tree @@ -157,7 +157,7 @@ describe("Widget module", function() { // Render the widget node to the DOM var wrapper = renderWidgetNode(widgetNode); // Test the rendering - expect(wrapper.innerHTML).toBe("Recursive transclusion error in transclude widget\n"); + expect(wrapper.innerHTML).toBe("Recursive transclusion error in transclude widget"); }); it("should deal with SVG elements", function() { @@ -683,7 +683,7 @@ describe("Widget module", function() { expect(wrapper.innerHTML).toBe("

New value

"); }); - it("should can mix setWidgets and macros when importing", function() { + it("should support mixed setWidgets and macros when importing", function() { var wiki = new $tw.Wiki(); // Add some tiddlers wiki.addTiddlers([ @@ -699,6 +699,20 @@ describe("Widget module", function() { expect(wrapper.innerHTML).toBe("

Aval Bval Cval

"); }); + it("should skip parameters widgets when importing", function() { + var wiki = new $tw.Wiki(); + // Add some tiddlers + wiki.addTiddlers([ + {title: "B", text: "<$parameters bee=nothing><$set name='B' value='Bval'>\n\ndummy text"}, + ]); + var text = "\\import B\n<>"; + var widgetNode = createWidgetNode(parseText(text,wiki),wiki); + // Render the widget node to the DOM + var wrapper = renderWidgetNode(widgetNode); + // Test the rendering + expect(wrapper.innerHTML).toBe("

Bval

"); + }); + it("can have more than one macroDef variable imported", function() { var wiki = new $tw.Wiki(); wiki.addTiddlers([ diff --git a/editions/test/tiddlers/tests/test-wikitext-parser.js b/editions/test/tiddlers/tests/test-wikitext-parser.js index 7f1551c28..bc3d9acd8 100644 --- a/editions/test/tiddlers/tests/test-wikitext-parser.js +++ b/editions/test/tiddlers/tests/test-wikitext-parser.js @@ -19,7 +19,8 @@ describe("WikiText parser tests", function() { // Define a parsing shortcut var parse = function(text) { - return wiki.parseText("text/vnd.tiddlywiki",text).tree; + var tree = wiki.parseText("text/vnd.tiddlywiki",text).tree; + return tree; }; it("should parse tags", function() { @@ -114,7 +115,70 @@ describe("WikiText parser tests", function() { it("should parse macro definitions", function() { expect(parse("\\define myMacro()\nnothing\n\\end\n")).toEqual( - [ { type : 'set', attributes : { name : { type : 'string', value : 'myMacro' }, value : { type : 'string', value : 'nothing' } }, children : [ ], params : [ ], isMacroDefinition : true } ] + [{"type":"set","attributes":{"name":{"name":"name","type":"string","value":"myMacro"},"value":{"name":"value","type":"string","value":"nothing"}},"children":[],"params":[],"isMacroDefinition":true,"orderedAttributes":[{"name":"name","type":"string","value":"myMacro"},{"name":"value","type":"string","value":"nothing"}]}] + + ); + }); + + it("should parse procedure definitions with no parameters", function() { + expect(parse("\\procedure myMacro()\nnothing\n\\end\n")).toEqual( + + [{"type":"set","attributes":{"name":{"name":"name","type":"string","value":"myMacro"},"value":{"name":"value","type":"string","value":"nothing"}},"children":[],"params":[],"orderedAttributes":[{"name":"name","type":"string","value":"myMacro"},{"name":"value","type":"string","value":"nothing"}],"isProcedureDefinition":true}] + + ); + }); + + it("should parse single line procedure definitions with no parameters", function() { + expect(parse("\\procedure myMacro() nothing\n")).toEqual( + + [{"type":"set","attributes":{"name":{"name":"name","type":"string","value":"myMacro"},"value":{"name":"value","type":"string","value":"nothing"}},"children":[],"params":[],"orderedAttributes":[{"name":"name","type":"string","value":"myMacro"},{"name":"value","type":"string","value":"nothing"}],"isProcedureDefinition":true}] + + ); + }); + + it("should parse procedure definitions with parameters", function() { + expect(parse("\\procedure myMacro(one,two,three,four:elephant)\nnothing\n\\end\n")).toEqual( + + [{"type":"set","attributes":{"name":{"name":"name","type":"string","value":"myMacro"},"value":{"name":"value","type":"string","value":"nothing"}},"children":[],"params":[{"name":"one"},{"name":"two"},{"name":"three"},{"name":"four","default":"elephant"}],"orderedAttributes":[{"name":"name","type":"string","value":"myMacro"},{"name":"value","type":"string","value":"nothing"}],"isProcedureDefinition":true}] + + ); + }); + + it("should parse procedure definitions", function() { + expect(parse("\\procedure myMacro(one:'Jaguar')\n<$text text=<>/>\n\\end\n\n")).toEqual( + + [{"type":"set","attributes":{"name":{"name":"name","type":"string","value":"myMacro"},"value":{"name":"value","type":"string","value":"<$text text=<>/>"}},"children":[],"params":[{"name":"one","default":"Jaguar"}],"orderedAttributes":[{"name":"name","type":"string","value":"myMacro"},{"name":"value","type":"string","value":"<$text text=<>/>"}],"isProcedureDefinition":true}] + + ); + + }); it("should parse function definitions with no parameters", function() { + expect(parse("\\function myMacro()\nnothing\n\\end\n")).toEqual( + + [{"type":"set","attributes":{"name":{"name":"name","type":"string","value":"myMacro"},"value":{"name":"value","type":"string","value":"nothing"}},"children":[],"params":[],"orderedAttributes":[{"name":"name","type":"string","value":"myMacro"},{"name":"value","type":"string","value":"nothing"}],"isFunctionDefinition":true}] + + ); + }); + + it("should parse single line function definitions with no parameters", function() { + expect(parse("\\function myMacro() nothing\n")).toEqual( + + [{"type":"set","attributes":{"name":{"name":"name","type":"string","value":"myMacro"},"value":{"name":"value","type":"string","value":"nothing"}},"children":[],"params":[],"orderedAttributes":[{"name":"name","type":"string","value":"myMacro"},{"name":"value","type":"string","value":"nothing"}],"isFunctionDefinition":true}] + + ); + }); + + it("should parse function definitions with parameters", function() { + expect(parse("\\function myMacro(one,two,three,four:elephant)\nnothing\n\\end\n")).toEqual( + + [{"type":"set","attributes":{"name":{"name":"name","type":"string","value":"myMacro"},"value":{"name":"value","type":"string","value":"nothing"}},"children":[],"params":[{"name":"one"},{"name":"two"},{"name":"three"},{"name":"four","default":"elephant"}],"orderedAttributes":[{"name":"name","type":"string","value":"myMacro"},{"name":"value","type":"string","value":"nothing"}],"isFunctionDefinition":true}] + + ); + }); + + it("should parse function definitions", function() { + expect(parse("\\function myMacro(one:'Jaguar')\n<$text text=<>/>\n\\end\n\n")).toEqual( + + [{"type":"set","attributes":{"name":{"name":"name","type":"string","value":"myMacro"},"value":{"name":"value","type":"string","value":"<$text text=<>/>"}},"children":[],"params":[{"name":"one","default":"Jaguar"}],"orderedAttributes":[{"name":"name","type":"string","value":"myMacro"},{"name":"value","type":"string","value":"<$text text=<>/>"}],"isFunctionDefinition":true}] ); }); @@ -122,7 +186,7 @@ describe("WikiText parser tests", function() { it("should parse comment in pragma area. Comment will be invisible", function() { expect(parse("\n\\define aMacro()\nnothing\n\\end\n")).toEqual( - [ { type : 'set', attributes : { name : { type : 'string', value : 'aMacro' }, value : { type : 'string', value : 'nothing' } }, children : [ ], params : [ ], isMacroDefinition : true } ] + [{"type":"set","attributes":{"name":{"name":"name","type":"string","value":"aMacro"},"value":{"name":"value","type":"string","value":"nothing"}},"children":[],"params":[],"isMacroDefinition":true,"orderedAttributes":[{"name":"name","type":"string","value":"aMacro"},{"name":"value","type":"string","value":"nothing"}]}] ); }); @@ -143,38 +207,38 @@ describe("WikiText parser tests", function() { it("should parse inline macro calls", function() { expect(parse("<><><><>")).toEqual( - [ { type: 'element', tag: 'p', start: 0, end: 35, children: [ { type: 'macrocall', start: 0, params: [ ], name: 'john', end: 8 }, { type: 'macrocall', start: 8, params: [ ], name: 'paul', end: 16 }, { type: 'macrocall', start: 16, params: [ ], name: 'george', end: 26 }, { type: 'macrocall', start: 26, params: [ ], name: 'ringo', end: 35 } ] } ] + [{"type":"element","tag":"p","children":[{"type":"transclude","start":0,"end":8,"attributes":{"$variable":{"name":"$variable","type":"string","value":"john"}},"orderedAttributes":[{"name":"$variable","type":"string","value":"john"}]},{"type":"transclude","start":8,"end":16,"attributes":{"$variable":{"name":"$variable","type":"string","value":"paul"}},"orderedAttributes":[{"name":"$variable","type":"string","value":"paul"}]},{"type":"transclude","start":16,"end":26,"attributes":{"$variable":{"name":"$variable","type":"string","value":"george"}},"orderedAttributes":[{"name":"$variable","type":"string","value":"george"}]},{"type":"transclude","start":26,"end":35,"attributes":{"$variable":{"name":"$variable","type":"string","value":"ringo"}},"orderedAttributes":[{"name":"$variable","type":"string","value":"ringo"}]}],"start":0,"end":35}] ); expect(parse("text <>")).toEqual( - [{ type: 'element', tag: 'p', start: 0, end: 92, children: [ { type: 'text', text: 'text ', start: 0, end: 5 }, { type: 'macrocall', name: 'john', start: 5, params: [ { type: 'macro-parameter', start: 11, value: 'val1', name: 'one', end: 20 }, { type: 'macro-parameter', start: 20, value: 'val "2"', name: 'two', end: 35 }, { type: 'macro-parameter', start: 35, value: 'val \'3\'', name: 'three', end: 52 }, { type: 'macro-parameter', start: 52, value: 'val 4"5\'', name: 'four', end: 73 }, { type: 'macro-parameter', start: 73, value: 'val 5', name: 'five', end: 89 } ], end: 92 } ] } ] + [{"type":"element","tag":"p","children":[{"type":"text","text":"text ","start":0,"end":5},{"type":"transclude","start":5,"end":92,"attributes":{"$variable":{"name":"$variable","type":"string","value":"john"},"one":{"name":"one","type":"string","value":"val1","start":11,"end":20},"two":{"name":"two","type":"string","value":"val \"2\"","start":20,"end":35},"three":{"name":"three","type":"string","value":"val '3'","start":35,"end":52},"four":{"name":"four","type":"string","value":"val 4\"5'","start":52,"end":73},"five":{"name":"five","type":"string","value":"val 5","start":73,"end":89}},"orderedAttributes":[{"name":"$variable","type":"string","value":"john"},{"name":"one","type":"string","value":"val1","start":11,"end":20},{"name":"two","type":"string","value":"val \"2\"","start":20,"end":35},{"name":"three","type":"string","value":"val '3'","start":35,"end":52},{"name":"four","type":"string","value":"val 4\"5'","start":52,"end":73},{"name":"five","type":"string","value":"val 5","start":73,"end":89}]}],"start":0,"end":92}] ); expect(parse("ignored << carrots <>")).toEqual( - [ { type: 'element', tag: 'p', start: 0, end: 27, children: [ { type: 'text', text: 'ignored << carrots ', start: 0, end: 19 }, { type: 'macrocall', name: 'john', start: 19, params: [ ], end: 27 } ] } ] + [{"type":"element","tag":"p","children":[{"type":"text","text":"ignored << carrots ","start":0,"end":19},{"type":"transclude","start":19,"end":27,"attributes":{"$variable":{"name":"$variable","type":"string","value":"john"}},"orderedAttributes":[{"name":"$variable","type":"string","value":"john"}]}],"start":0,"end":27}] ); expect(parse("text <<>")).toEqual( - [ { type: 'element', tag: 'p', start: 0, end: 14, children: [ { type: 'text', text: 'text ', start: 0, end: 5 }, { type: 'macrocall', name: '>")).toEqual( - [ { type: 'element', tag: 'p', start: 0, end: 15, children: [ { type: 'text', text: 'before\n', start: 0, end: 7 }, { type: 'macrocall', start: 7, params: [ ], name: 'john', end: 15 } ] } ] + [{"type":"element","tag":"p","children":[{"type":"text","text":"before\n","start":0,"end":7},{"type":"transclude","start":7,"end":15,"attributes":{"$variable":{"name":"$variable","type":"string","value":"john"}},"orderedAttributes":[{"name":"$variable","type":"string","value":"john"}]}],"start":0,"end":15}] ); // A single space will cause it to be inline expect(parse("<> ")).toEqual( - [ { type: 'element', tag: 'p', start: 0, end: 9, children: [ { type: 'macrocall', start: 0, params: [ ], name: 'john', end: 8 }, { type: 'text', text: ' ', start: 8, end: 9 } ] } ] + [{"type":"element","tag":"p","children":[{"type":"transclude","start":0,"end":8,"attributes":{"$variable":{"name":"$variable","type":"string","value":"john"}},"orderedAttributes":[{"name":"$variable","type":"string","value":"john"}]},{"type":"text","text":" ","start":8,"end":9}],"start":0,"end":9}] ); expect(parse("text <>' >>")).toEqual( - [ { type: 'element', tag: 'p', start: 0, end: 34, children: [ { type: 'text', text: 'text ', start: 0, end: 5 }, { type: 'macrocall', start: 5, params: [ { type: 'macro-parameter', start: 12, value: 'my <>', name: 'one', end: 31 } ], name: 'outie', end: 34 } ] } ] + [{"type":"element","tag":"p","children":[{"type":"text","text":"text ","start":0,"end":5},{"type":"transclude","start":5,"end":34,"attributes":{"$variable":{"name":"$variable","type":"string","value":"outie"},"one":{"name":"one","type":"string","value":"my <>","start":12,"end":31}},"orderedAttributes":[{"name":"$variable","type":"string","value":"outie"},{"name":"one","type":"string","value":"my <>","start":12,"end":31}]}],"start":0,"end":34}] ); @@ -183,37 +247,37 @@ describe("WikiText parser tests", function() { it("should parse block macro calls", function() { expect(parse("<>\n<>\r\n<>\n<>")).toEqual( - [ { type: 'macrocall', start: 0, name: 'john', params: [ ], end: 8, isBlock: true }, { type: 'macrocall', start: 9, name: 'paul', params: [ ], end: 17, isBlock: true }, { type: 'macrocall', start: 19, name: 'george', params: [ ], end: 29, isBlock: true }, { type: 'macrocall', start: 30, name: 'ringo', params: [ ], end: 39, isBlock: true } ] + [ { type: 'transclude', start: 0, attributes: { $variable: { name: "$variable", type: "string", value: "john" }}, orderedAttributes: [ { name: "$variable", type: "string", value: "john" }], end: 8, isBlock: true }, { type: 'transclude', start: 9, attributes: { $variable: { name: "$variable", type: "string", value: "paul" }}, orderedAttributes: [ { name: "$variable", type: "string", value: "paul" }], end: 17, isBlock: true }, { type: 'transclude', start: 19, attributes: { $variable: { name: "$variable", type: "string", value: "george" }}, orderedAttributes: [ { name: "$variable", type: "string", value: "george" }], end: 29, isBlock: true }, { type: 'transclude', start: 30, attributes: { $variable: { name: "$variable", type: "string", value: "ringo" }}, orderedAttributes: [ { name: "$variable", type: "string", value: "ringo" }], end: 39, isBlock: true } ] ); expect(parse("<>")).toEqual( - [ { type: 'macrocall', start: 0, name: 'john', params: [ { type: 'macro-parameter', start: 6, value: 'val1', name: 'one', end: 15 }, { type: 'macro-parameter', start: 15, value: 'val "2"', name: 'two', end: 30 }, { type: 'macro-parameter', start: 30, value: 'val \'3\'', name: 'three', end: 47 }, { type: 'macro-parameter', start: 47, value: 'val 4"5\'', name: 'four', end: 68 }, { type: 'macro-parameter', start: 68, value: 'val 5', name: 'five', end: 84 }], end: 87, isBlock: true } ] + [{"type":"transclude","start":0,"end":87,"attributes":{"$variable":{"name":"$variable","type":"string","value":"john"},"one":{"name":"one","type":"string","value":"val1","start":6,"end":15},"two":{"name":"two","type":"string","value":"val \"2\"","start":15,"end":30},"three":{"name":"three","type":"string","value":"val '3'","start":30,"end":47},"four":{"name":"four","type":"string","value":"val 4\"5'","start":47,"end":68},"five":{"name":"five","type":"string","value":"val 5","start":68,"end":84}},"orderedAttributes":[{"name":"$variable","type":"string","value":"john"},{"name":"one","type":"string","value":"val1","start":6,"end":15},{"name":"two","type":"string","value":"val \"2\"","start":15,"end":30},{"name":"three","type":"string","value":"val '3'","start":30,"end":47},{"name":"four","type":"string","value":"val 4\"5'","start":47,"end":68},{"name":"five","type":"string","value":"val 5","start":68,"end":84}],"isBlock":true}] ); expect(parse("<< carrots\n\n<>")).toEqual( - [ { type: 'element', tag: 'p', start : 0, end : 10, children: [ { type: 'text', text: '<< carrots', start : 0, end : 10 } ] }, { type: 'macrocall', start: 12, params: [ ], name: 'john', end: 20, isBlock: true } ] + [ { type: 'element', tag: 'p', start : 0, end : 10, children: [ { type: 'text', text: '<< carrots', start : 0, end : 10 } ] }, { type: 'transclude', start: 12, attributes: { $variable: {name: "$variable", type:"string", value: "john"} }, orderedAttributes: [ {name: "$variable", type:"string", value: "john"} ], end: 20, isBlock: true } ] ); expect(parse("before\n\n<>")).toEqual( - [ { type: 'element', tag: 'p', start : 0, end : 6, children: [ { type: 'text', text: 'before', start : 0, end : 6 } ] }, { type: 'macrocall', start: 8, name: 'john', params: [ ], end: 16, isBlock: true } ] + [ { type: 'element', tag: 'p', start : 0, end : 6, children: [ { type: 'text', text: 'before', start : 0, end : 6 } ] }, { type: 'transclude', start: 8, attributes: { $variable: {name: "$variable", type:"string", value: "john"} }, orderedAttributes: [ {name: "$variable", type:"string", value: "john"} ], end: 16, isBlock: true } ] ); expect(parse("<>\nafter")).toEqual( - [ { type: 'macrocall', start: 0, name: 'john', params: [ ], end: 8, isBlock: true }, { type: 'element', tag: 'p', start: 9, end: 14, children: [ { type: 'text', text: 'after', start: 9, end: 14 } ] } ] + [ { type: 'transclude', start: 0, attributes: { $variable: {name: "$variable", type:"string", value: "john"} }, orderedAttributes: [ {name: "$variable", type:"string", value: "john"} ], end: 8, isBlock: true }, { type: 'element', tag: 'p', start: 9, end: 14, children: [ { type: 'text', text: 'after', start: 9, end: 14 } ] } ] ); expect(parse("<>")).toEqual( - [ { type: 'macrocall', start: 0, params: [ { type: 'macro-parameter', start: 11, value: '\n\nwikitext\n', name: 'arg', end: 33 } ], name: 'multiline', end: 36, isBlock: true }] + [{"type":"transclude","start":0,"end":36,"attributes":{"$variable":{"name":"$variable","type":"string","value":"multiline"},"arg":{"name":"arg","type":"string","value":"\n\nwikitext\n","start":11,"end":33}},"orderedAttributes":[{"name":"$variable","type":"string","value":"multiline"},{"name":"arg","type":"string","value":"\n\nwikitext\n","start":11,"end":33}],"isBlock":true}] ); expect(parse("<>' >>")).toEqual( - [ { type: 'macrocall', start: 0, params: [ { type: 'macro-parameter', start: 7, value: 'my <>', name: 'one', end: 26 } ], name: 'outie', end: 29, isBlock: true } ] + [ { type: 'transclude', start: 0, attributes: { $variable: {name: "$variable", type:"string", value: "outie"}, one: {name: "one", type:"string", value: "my <>", start: 7, end: 26} }, orderedAttributes: [ {name: "$variable", type:"string", value: "outie"}, {name: "one", type:"string", value: "my <>", start: 7, end: 26} ], end: 29, isBlock: true } ] ); }); @@ -221,23 +285,23 @@ describe("WikiText parser tests", function() { it("should parse tricky macrocall parameters", function() { expect(parse("<am>>")).toEqual( - [ { type: 'macrocall', start: 0, params: [ { type: 'macro-parameter', start: 6, value: 'pa>am', end: 12 } ], name: 'john', end: 14, isBlock: true } ] + [{"type":"transclude","start":0,"end":14,"attributes":{"0":{"name":"0","type":"string","value":"pa>am","start":6,"end":12},"$variable":{"name":"$variable","type":"string","value":"john"}},"orderedAttributes":[{"name":"$variable","type":"string","value":"john"},{"name":"0","type":"string","value":"pa>am","start":6,"end":12}],"isBlock":true}] ); expect(parse("< >>")).toEqual( - [ { type: 'macrocall', start: 0, params: [ { type: 'macro-parameter', start: 6, value: 'param>', end: 13 } ], name: 'john', end: 16, isBlock: true } ] + [{"type":"transclude","start":0,"end":16,"attributes":{"0":{"name":"0","type":"string","value":"param>","start":6,"end":13},"$variable":{"name":"$variable","type":"string","value":"john"}},"orderedAttributes":[{"name":"$variable","type":"string","value":"john"},{"name":"0","type":"string","value":"param>","start":6,"end":13}],"isBlock":true}] ); expect(parse("<>>")).toEqual( - [ { type: 'element', tag: 'p', start: 0, end: 15, children: [ { type: 'macrocall', start: 0, params: [ { type: 'macro-parameter', start: 6, value: 'param', end: 12 } ], name: 'john', end: 14 }, { type: 'text', text: '>', start: 14, end: 15 } ] } ] + [{"type":"element","tag":"p","children":[{"type":"transclude","start":0,"end":14,"attributes":{"0":{"name":"0","type":"string","value":"param","start":6,"end":12},"$variable":{"name":"$variable","type":"string","value":"john"}},"orderedAttributes":[{"name":"$variable","type":"string","value":"john"},{"name":"0","type":"string","value":"param","start":6,"end":12}]},{"type":"text","text":">","start":14,"end":15}],"start":0,"end":15}] ); // equals signs should be allowed expect(parse("<=4 >>")).toEqual( - [ { type: 'macrocall', start: 0, params: [ { type: 'macro-parameter', start: 6, value: 'var>=4', end: 13 } ], name: 'john', end: 16, isBlock: true } ] + [{"type":"transclude","start":0,"end":16,"attributes":{"0":{"name":"0","type":"string","value":"var>=4","start":6,"end":13},"$variable":{"name":"$variable","type":"string","value":"john"}},"orderedAttributes":[{"name":"$variable","type":"string","value":"john"},{"name":"0","type":"string","value":"var>=4","start":6,"end":13}],"isBlock":true}] ); diff --git a/editions/test/tiddlers/tests/test-wikitext-tabs-macro.js b/editions/test/tiddlers/tests/test-wikitext-tabs-macro.js index b37f402cc..39f061d11 100644 --- a/editions/test/tiddlers/tests/test-wikitext-tabs-macro.js +++ b/editions/test/tiddlers/tests/test-wikitext-tabs-macro.js @@ -1,7 +1,7 @@ /*\ title: test-wikitext-tabs-macro.js type: application/javascript -tags: [[$:/tags/test-spec]] +tags: [[$:/tags/test-spec-disabled]] Tests the core tabs macro by comparing the HTML output with a stored template. Intended to permit future readability improvements. @@ -74,7 +74,7 @@ describe("Tabs-macro HTML tests", function() { expect(wiki.renderTiddler("text/html","test-tabs-macro-horizontal")).toBe(expected.fields.text.replace(/\n/g,"")); }); - it("should render 'horizontal' tabs from v5.2.2 and up with whitespace trim", function() { + it("should render all 'horizontal' tabs from v5.2.2 and up with whitespace trim", function() { expect(wiki.renderTiddler("text/html","test-tabs-macro-horizontal-all")).toBe(expectedAll.fields.text.replace(/\n/g,"")); }); diff --git a/editions/tw5.com/tiddlers/Brackets.tid b/editions/tw5.com/tiddlers/concepts/Brackets.tid similarity index 92% rename from editions/tw5.com/tiddlers/Brackets.tid rename to editions/tw5.com/tiddlers/concepts/Brackets.tid index 529adb17e..fee36313c 100644 --- a/editions/tw5.com/tiddlers/Brackets.tid +++ b/editions/tw5.com/tiddlers/concepts/Brackets.tid @@ -10,5 +10,5 @@ WikiText syntax uses a number of different types of brackets. Their names are sh |`()` |Round brackets |Parenthesis |Not used in WikiText | |`[]` |Square brackets |Brackets |[[Links|Linking in WikiText]], [[Filters|Filters]] | |`{}` |Curly brackets |Braces |[[Text references|TextReference]], [[Filtered attributes|HTML in WikiText]] | -|`<>` |Angle brackets |Chevrons |[[HTML elements and widgets|HTML in WikiText]], [[Macros|Macros in WikiText]] | +|`<>` |Angle brackets |Chevrons |[[HTML elements and widgets|HTML in WikiText]], [[Macros]] | diff --git a/editions/tw5.com/tiddlers/concepts/Macros.tid b/editions/tw5.com/tiddlers/concepts/Macros.tid index 1d06f9755..8377046f6 100644 --- a/editions/tw5.com/tiddlers/concepts/Macros.tid +++ b/editions/tw5.com/tiddlers/concepts/Macros.tid @@ -1,31 +1,42 @@ created: 20140211171341271 -modified: 20220505082754270 +modified: 20230419103154328 tags: Concepts Reference title: Macros type: text/vnd.tiddlywiki -A <<.def macro>> is a named snippet of text. WikiText can use the name as a shorthand way of [[transcluding|Transclusion]] the snippet. Such transclusions are known as <<.def "macro calls">>, and each call can supply a different set of parameters that get substituted for special placeholders within the snippet. +!! Introduction -For the syntax, see [[Macros in WikiText]]. +A <<.def macro>> is a named snippet of text. They are typically defined with the [[Pragma: \define]]: -Most macros are in fact just parameterised [[variables|Variables]]. +``` +\define my-macro(parameter:"Default value") +This is the macro, and the parameter is $parameter$. +\end +``` -They are created using the `\define` [[pragma|Pragma]]. (Behind the scenes, this is transformed into a <<.wlink SetWidget>>, i.e. macros and variables are two sides of the same coin.) +The name wrapped in double angled [[brackets|Brackets]] is used a shorthand way of [[transcluding|Transclusion]] the snippet. Such transclusions are known as <<.def "macro calls">>, and each call can supply a different set of parameters: -The snippet and its incoming parameter values are treated as simple strings of characters with no WikiText meaning, at least until the placeholders have been filled in and the macro call has returned. This means that a macro can assemble and return the complete syntax of a ~WikiText component, such as a [[link|Linking in WikiText]]. (See [[Transclusion and Substitution]] for further discussion of this.) +``` +<> +<> +``` -Within a snippet itself, the only markup detected is `$name$` (a placeholder for a macro parameter) and `$(name)$` (a placeholder for a [[variable|Variables]]). +The parameters that are specified in the macro call are substituted for special placeholders within the snippet: -The <<.mlink dumpvariables>> macro lists all variables (including macros) that are available at that position in the widget tree. +* `$parameter-name$` is replaced with the value of the named parameter +* `$(variable-name)$` is replaced with the value of the named [[variable|Variables]]). -An <<.wlink ImportVariablesWidget>> widget can be used to copy macro definitions to another branch of the [[widget tree|Widgets]]. ~TiddlyWiki uses this technique internally to implement global macros -- namely any macros defined in tiddlers with the <<.tag $:/tags/Macro>> tag. +<<.from-version "5.3.0">> Macros have been [[superseded|Macro Pitfalls]] by [[Procedures]], [[Custom Widgets]] and [[Functions]] which together provide more robust and flexible ways to encapsulate and re-use code. It is now recommended to only use macros when textual substitution is specifically required. -The tag <<.tag $:/tags/Macro/View>> is used to define macros that should only be available within the main view template and the preview panel. +!! How Macros Work -The tag <<.tag $:/tags/Macro/View/Body>> is used to define macros that should only be available within the main view template body and the preview panel. +Macros are implemented as a special kind of [[variable|Variables]]. The only thing that distinguishes them from ordinary variables is the way that the parameters are handled. -For maximum flexibility, macros can also be <<.js-macro-link "written as JavaScript modules">>. +!! Using Macros -A similar effect to a parameterised macro call can be produced by setting [[variables|Variables]] around a [[transclusion|Transclusion]]. +* [[Macro Definitions]] describes how to create macros +* [[Macro Calls]] describes how to use macros +* [[Macro Parameter Handling]] describes how macro parameters work +* [[Macro Pitfalls]] describes some of the pitfalls of using macros +* [[Core Macros]] lists the built-in core macros -~TiddlyWiki's core has [[several macros|Core Macros]] built in. diff --git a/editions/tw5.com/tiddlers/concepts/Pragma.tid b/editions/tw5.com/tiddlers/concepts/Pragma.tid index 3a9e1de12..868cf9667 100644 --- a/editions/tw5.com/tiddlers/concepts/Pragma.tid +++ b/editions/tw5.com/tiddlers/concepts/Pragma.tid @@ -1,24 +1,8 @@ + created: 20150219175930000 -modified: 20230117112239663 -tags: Concepts [[WikiText Parser Modes]] +modified: 20220122182842041 +tags: title: Pragma type: text/vnd.tiddlywiki -A <<.def pragma>> is a special component of WikiText that provides control over the way the remaining text is parsed. - -Pragmas occupy lines that start with `\`. They can only appear at the start of the text, but blank lines are allowed between them. If a pragma line appears in the main body of the text, it is treated as if it was ordinary text. -<<.from-version "5.2.6">> Pragmas can have preceding optional whitespace characters. - - -The following pragmas are available: - -;`\define` -: for defining a [[macro|Macros]] -;`\rules` -: for adjusting the set of rules used to parse the text -;`\whitespace trim` or `\whitespace notrim` -: <<.from-version "5.1.15">> Control whether whitespace is trimmed from the start and end of text runs (the default is ''notrim''). This setting can be useful when the whitespace generated by linebreaks disturbs formatting -;`\import ` -: <<.from-version "5.1.18">> Import macro definitions from tiddlers identified by a filter expression -;`\parsermode block` or `\parsermode inline` -: <<.from-version "5.2.4">> Adjust whether the remaining text is parsed in block mode or inline mode. \ No newline at end of file +See [[Pragmas]]. diff --git a/editions/tw5.com/tiddlers/definitions/Tiddlyhost.tid b/editions/tw5.com/tiddlers/definitions/Tiddlyhost.tid index cb644b88c..8dee477da 100644 --- a/editions/tw5.com/tiddlers/definitions/Tiddlyhost.tid +++ b/editions/tw5.com/tiddlers/definitions/Tiddlyhost.tid @@ -1,5 +1,5 @@ title: Tiddlyhost -tags: definition +tags: Definitions created: 20230410105035569 modified: 20230410105035569 diff --git a/editions/tw5.com/tiddlers/definitions/Xememex.tid b/editions/tw5.com/tiddlers/definitions/Xememex.tid index 3ca994400..5457f23cc 100644 --- a/editions/tw5.com/tiddlers/definitions/Xememex.tid +++ b/editions/tw5.com/tiddlers/definitions/Xememex.tid @@ -5,7 +5,7 @@ modified: 20230410105035569 [img width=340 [Xememex Logo]] -Xememex is a multiuser TiddlyWiki from [[Federatial]]. It allows large groups of people to work together on intertwingled wikis that can share content. +Xememex is a multiuser TiddlyWiki from [[Federatial]]. It allows large groups of people to work together on intertwingled wikis that can share content. It is implemented as a serverless application on Amazon Web Services. The largest customer implementation has hundreds of online wikis with thousands of users. See https://manuals.annafreud.org/ diff --git a/editions/tw5.com/tiddlers/features/StartupActions.tid b/editions/tw5.com/tiddlers/features/StartupActions.tid index 79a23b3d9..29edb8378 100644 --- a/editions/tw5.com/tiddlers/features/StartupActions.tid +++ b/editions/tw5.com/tiddlers/features/StartupActions.tid @@ -33,7 +33,7 @@ The initial startup actions are useful for customising TiddlyWiki according to e <$action-setfield $tiddler="$:/language" text={{{ [[$:/languages/en-GB]] [plugin-type[language]sort[description]removeprefix[$:/languages/]] +[prefix{$:/info/browser/language}] ~[[en-GB]] +[addprefix[$:/languages/]] }}}/> ``` -Note that global macros are not available within initial startup action tiddlers by default. If you need to access them then you'll need to explicitly include them with an ''import'' [[pragma|Pragma]] at the top of the tiddler: +Note that global macros are not available within initial startup action tiddlers by default. If you need to access them then you'll need to explicitly include them with an [[Pragma: \import]] at the top of the tiddler: ``` \import [[$:/core/ui/PageMacros]] [all[shadows+tiddlers]tag[$:/tags/Macro]!has[draft.of]] diff --git a/editions/tw5.com/tiddlers/filters/function.tid b/editions/tw5.com/tiddlers/filters/function.tid new file mode 100644 index 000000000..f86d21f4f --- /dev/null +++ b/editions/tw5.com/tiddlers/filters/function.tid @@ -0,0 +1,21 @@ +caption: function +created: 20220909111836951 +modified: 20230419103154328 +op-input: a [[selection of titles|Title Selection]] passed as input to the function <<.place F>> +op-output: the [[selection of titles|Title Selection]] returned from the function <<.place F>> +op-parameter: first parameter is the [[function name|Functions]], subsequent parameters are passed to the function by position +op-parameter-name: F +op-purpose: apply a [[function|Functions]] to the input list, and return the result +tags: [[Filter Operators]] +title: function Operator +type: text/vnd.tiddlywiki + +<<.from-version "5.3.0">> The <<.op function>> operator applies a named [[function|Functions]] to the input titles, and returns the results from the function. The function is invoked once with all of the input titles (in contrast, the [[filter Operator]] invokes its function separately for each input title). + +The first parameter of the <<.op function>> operator specifies the name of the function to be called. Subsequent parameters are passed to the function. + +The mapping between the parameters is //positional//, with each consecutive parameter specified in the function call mapped to the corresponding parameter in the function definition. Any parameters that are not provided are given their default values. + +<<.tip "Compare with the similar [[filter|filter Operator]] and [[subfilter|subfilter Operator]] operators which take a filter strings as their parameter instead of a named function, and does not permit parameters to be passed">> + +<<.operator-examples "function">> diff --git a/editions/tw5.com/tiddlers/functions/Functions.tid b/editions/tw5.com/tiddlers/functions/Functions.tid new file mode 100644 index 000000000..3b06dddc7 --- /dev/null +++ b/editions/tw5.com/tiddlers/functions/Functions.tid @@ -0,0 +1,28 @@ +created: 20221009124003601 +modified: 20230419103154328 +tags: Concepts Reference +title: Functions +type: text/vnd.tiddlywiki + +!! Introduction + +<<.from-version "5.3.0">> A <<.def function>> is a named snippet of text containing a [[Filter Expression]]. Functions can have named parameters which are available within the function as variables. + +Functions are usually defined with the [[Pragma: \function]]: + +``` +\function my-function(parameter:"2") +[multiply[1.5]] +\end +``` + +Functions can be invoked in several ways: + +* Directly transclude functions with the syntax `<>` +* Assign functions to widget attributes with the syntax ` !! ''Testimonials & Reviews'' diff --git a/editions/tw5.com/tiddlers/howtos/Visible Transclusions.tid b/editions/tw5.com/tiddlers/howtos/Visible Transclusions.tid new file mode 100644 index 000000000..e3f46440e --- /dev/null +++ b/editions/tw5.com/tiddlers/howtos/Visible Transclusions.tid @@ -0,0 +1,14 @@ +created: 20220909111836951 +modified: 20230419103154329 +tags: Learning +title: Visible Transclusions +type: text/vnd.tiddlywiki + +!! Visible Transclusions + +Block transclusions are shown in red, and inline transclusions are shown in green. + +<$button> +<$action-setfield $tiddler="$:/temp/VisibleTransclusions" tags="$:/tags/Macro/View/Body" text={{$:/core/ui/VisibleTransclude}}/> +Click here to make transclusions visible within story river tiddlers + diff --git a/editions/tw5.com/tiddlers/images/New Release Banner.png b/editions/tw5.com/tiddlers/images/New Release Banner.png index 74e2557d8..b75c8fc19 100644 Binary files a/editions/tw5.com/tiddlers/images/New Release Banner.png and b/editions/tw5.com/tiddlers/images/New Release Banner.png differ diff --git a/editions/tw5.com/tiddlers/images/Open Collective Logo.tid b/editions/tw5.com/tiddlers/images/Open Collective Logo.tid new file mode 100644 index 000000000..25e91161a --- /dev/null +++ b/editions/tw5.com/tiddlers/images/Open Collective Logo.tid @@ -0,0 +1,4 @@ +title: Open Collective Logo +tags: picture + + \ No newline at end of file diff --git a/editions/tw5.com/tiddlers/macros/import/say-hi-using-variables.tid b/editions/tw5.com/tiddlers/macros/import/say-hi-using-variables.tid index 4aa265fa3..11064f388 100644 --- a/editions/tw5.com/tiddlers/macros/import/say-hi-using-variables.tid +++ b/editions/tw5.com/tiddlers/macros/import/say-hi-using-variables.tid @@ -1,3 +1,4 @@ +code-body: yes created: 20150221145447000 modified: 20150221145626000 title: $:/editions/tw5.com/macro-examples/say-hi-using-variables diff --git a/editions/tw5.com/tiddlers/macros/import/say-hi.tid b/editions/tw5.com/tiddlers/macros/import/say-hi.tid index 2d2d31afc..55db4cc9a 100644 --- a/editions/tw5.com/tiddlers/macros/import/say-hi.tid +++ b/editions/tw5.com/tiddlers/macros/import/say-hi.tid @@ -1,8 +1,9 @@ +code-body: yes created: 20150221145803000 modified: 20150221221536000 title: $:/editions/tw5.com/macro-examples/say-hi type: text/vnd.tiddlywiki -\define sayhi(name:"Bugs Bunny" address:"Rabbit Hole Hill") +\define sayhi(name:"Bugs Bunny",address:"Rabbit Hole Hill") Hi, I'm $name$ and I live in $address$. \end diff --git a/editions/tw5.com/tiddlers/macros/import/tags-of-current-tiddler.tid b/editions/tw5.com/tiddlers/macros/import/tags-of-current-tiddler.tid index b1bfc753c..860ad33db 100644 --- a/editions/tw5.com/tiddlers/macros/import/tags-of-current-tiddler.tid +++ b/editions/tw5.com/tiddlers/macros/import/tags-of-current-tiddler.tid @@ -1,3 +1,4 @@ +code-body: yes created: 20150221145803000 title: $:/editions/tw5.com/macro-examples/tags-of-current-tiddler type: text/vnd.tiddlywiki diff --git a/editions/tw5.com/tiddlers/macros/import/tv-wikilink-tooltip.tid b/editions/tw5.com/tiddlers/macros/import/tv-wikilink-tooltip.tid index 11b442b8c..9687f4b15 100644 --- a/editions/tw5.com/tiddlers/macros/import/tv-wikilink-tooltip.tid +++ b/editions/tw5.com/tiddlers/macros/import/tv-wikilink-tooltip.tid @@ -1,5 +1,5 @@ +code-body: yes created: 20150228120252000 -modified: 20150228120554000 title: $:/editions/tw5.com/macro-examples/tv-wikilink-tooltip type: text/vnd.tiddlywiki diff --git a/editions/tw5.com/tiddlers/pragmas/Pragma_ _define.tid b/editions/tw5.com/tiddlers/pragmas/Pragma_ _define.tid new file mode 100644 index 000000000..6058b7905 --- /dev/null +++ b/editions/tw5.com/tiddlers/pragmas/Pragma_ _define.tid @@ -0,0 +1,51 @@ +created: 20220917112233317 +modified: 20230419103154328 +tags: Pragmas +title: Pragma: \define +type: text/vnd.tiddlywiki + +The ''\define'' [[pragma|Pragmas]] is used to [[define macros|Macro Definitions]]. It is a shortcut syntax for the SetVariableWidget. + +The usual form allows macros to span multiple lines. + +``` +\define ([:],[:]...) + +\end [] +``` + +Note that the `\end` marker can optionally specify the name of the macro to which it relates which allows macro definitions to be nested. + +There is also a single line form for shorter macros: + +``` +\define ([:],[:]...) +``` + +The first line of the definition specifies the macro name and any parameters. Each parameter has a name and, optionally, a default value that is used if no value is supplied on a particular call to the macro. + +The lines that follow contain the text of the macro text (i.e. the snippet represented by the macro name), until `\end` appears on a line by itself: + +<$codeblock code={{$:/editions/tw5.com/macro-examples/say-hi}}/> + +Alternatively, the entire definition can be presented on a single line without an `\end` marker: + +``` +\define sayhi(name:"Bugs Bunny") Hi, I'm $name$. +``` + +Macro definitions can be nested by specifying the name of the macro in the `\end` marker. For example: + +< +\end actions +<$button actions=<>> +$caption$ + +\end special-button + +<> +""">> + +A more formal [[presentation|Macro Definition Syntax]] of this syntax is also available. diff --git a/editions/tw5.com/tiddlers/pragmas/Pragma_ _function.tid b/editions/tw5.com/tiddlers/pragmas/Pragma_ _function.tid new file mode 100644 index 000000000..253c8b452 --- /dev/null +++ b/editions/tw5.com/tiddlers/pragmas/Pragma_ _function.tid @@ -0,0 +1,27 @@ +created: 20221009162634214 +modified: 20230419103154329 +tags: Pragmas +title: Pragma: \function +type: text/vnd.tiddlywiki + +<<.from-version "5.3.0">> The ''\function'' [[pragma|Pragmas]] is used to [[define custom functions|Functions]]. It is a shortcut syntax for the SetVariableWidget. + +The usual form allows custom functions to span multiple lines: + +``` +\function ([:],[:]...) + +\end [] +``` + +Note that the `\end` marker can optionally specify the name of the function to which it relates, enabling function definitions to be nested inside procedures, macros or widget definitions. + +There is also a single line form for shorter functions: + +``` +\function ([:],[:]...) +``` + +The first line of the definition specifies the function name and any parameters. Each parameter has a name and, optionally, a default value that is used if no value is supplied on a particular call to the function. The lines that follow contain the text of the function (i.e. the snippet represented by the function name), until `\end` appears on a line by itself: + +See [[Functions]] for more details. \ No newline at end of file diff --git a/editions/tw5.com/tiddlers/pragmas/Pragma_ _import.tid b/editions/tw5.com/tiddlers/pragmas/Pragma_ _import.tid new file mode 100644 index 000000000..5971a5490 --- /dev/null +++ b/editions/tw5.com/tiddlers/pragmas/Pragma_ _import.tid @@ -0,0 +1,17 @@ +created: 20220917113054582 +modified: 20230419103154329 +tags: Pragmas +title: Pragma: \import +type: text/vnd.tiddlywiki + +The ''\import'' [[pragma|Pragmas]] is used to import definitions from other tiddlers that are identified with a filter. It is a shortcut syntax for the ImportVariablesWidget. + +``` +\import +``` + +For example: + +``` +\import [all[shadows+tiddlers]tag[$:/tags/Macro]] +``` diff --git a/editions/tw5.com/tiddlers/pragmas/Pragma_ _parameters.tid b/editions/tw5.com/tiddlers/pragmas/Pragma_ _parameters.tid new file mode 100644 index 000000000..5f32b06eb --- /dev/null +++ b/editions/tw5.com/tiddlers/pragmas/Pragma_ _parameters.tid @@ -0,0 +1,18 @@ +created: 20220917113154900 +modified: 20230419103154329 +tags: Pragmas +title: Pragma: \parameters +type: text/vnd.tiddlywiki + +<<.from-version "5.3.0">> The ''\parameters'' [[pragma|Pragmas]] is used within [[procedure|Procedure Definitions]] and [[widget|Widget Definitions]] definitions to declare the parameters that are expected, and their default values. It is a shortcut syntax for the ParametersWidget. + +``` +\parameters ([:],[:]...) +``` + +For example: + +``` +\parameters (firstname:"Joe",lastname:"Blogs") +``` + diff --git a/editions/tw5.com/tiddlers/pragmas/Pragma_ _procedure.tid b/editions/tw5.com/tiddlers/pragmas/Pragma_ _procedure.tid new file mode 100644 index 000000000..082bc466d --- /dev/null +++ b/editions/tw5.com/tiddlers/pragmas/Pragma_ _procedure.tid @@ -0,0 +1,55 @@ +created: 20221007132845007 +modified: 20230419103154329 +tags: Pragmas +title: Pragma: \procedure +type: text/vnd.tiddlywiki + +<<.from-version "5.3.0">> The ''\procedure'' [[pragma|Pragmas]] is used to [[define procedures|Procedure Definitions]]. It is a shortcut syntax for the SetVariableWidget with an implicit ParametersWidget. + +The usual form allows procedures to span multiple lines: + +``` +\procedure ([:],[:]...) + +\end [] +``` + +Note that the `\end` marker can optionally specify the name of the procedure to which it relates which allows procedure definitions to be nested. + +There is also a single line form for shorter procedures: + +``` +\define ([:],[:]...) +``` + +The first line of the definition specifies the procedure name and any parameters. Each parameter has a name and, optionally, a default value that is used if no value is supplied on a particular call to the procedure. The lines that follow contain the text of the procedure text (i.e. the snippet represented by the procedure name), until `\end` appears on a line by itself: + +For example: + +``` +\procedure sayhi(name:"Bugs Bunny") +Hi, I'm <>. +\end + +<> +``` + +Alternatively, the entire definition can be presented on a single line without an `\end` marker: + +``` +\procedure sayhi(name:"Bugs Bunny") Hi, I'm <>. +``` + +Procedure definitions can be nested by specifying the name of the procedure in the `\end` marker. For example: + +< +\end actions +<$button actions=<>> +<> + +\end special-button + +<> +""">> \ No newline at end of file diff --git a/editions/tw5.com/tiddlers/pragmas/Pragma_ _rules.tid b/editions/tw5.com/tiddlers/pragmas/Pragma_ _rules.tid new file mode 100644 index 000000000..799c9b71c --- /dev/null +++ b/editions/tw5.com/tiddlers/pragmas/Pragma_ _rules.tid @@ -0,0 +1,25 @@ +created: 20220917112931273 +modified: 20230419103154329 +tags: Pragmas +title: Pragma: \rules +type: text/vnd.tiddlywiki + +The ''\rules'' [[pragma|Pragmas]] adjusts the set of parser rules used to parse the remaining text. + +``` +\rules only|expect +``` + +The list of available parser rules can be consulted in $:/ControlPanel -> Info -> Advanced -> Parsing. + +For example, in stylesheets it is typical to only use the rules associated with macros and transclusions: + +``` +\rules only filteredtranscludeinline transcludeinline macrodef macrocallinline +``` + +Some users prefer not to use CamelCase links: + +``` +\rules except prettylink +``` \ No newline at end of file diff --git a/editions/tw5.com/tiddlers/pragmas/Pragma_ _whitespace.tid b/editions/tw5.com/tiddlers/pragmas/Pragma_ _whitespace.tid new file mode 100644 index 000000000..273a35bea --- /dev/null +++ b/editions/tw5.com/tiddlers/pragmas/Pragma_ _whitespace.tid @@ -0,0 +1,20 @@ +created: 20220917113002350 +modified: 20230419103154329 +tags: Pragmas +title: Pragma: \whitespace +type: text/vnd.tiddlywiki + +<<.from-version "5.1.15">> The ''\whitespace'' [[pragma|Pragmas]] determines how spaces and newlines are treated within wikitext. Note that this only applies to the printable text, and not to other text, such as the values of attributes. + +* ''notrim'' -- whitespace text is not subject to special processing (the default) +* ''trim'' -- whitespace text is removed + +``` +\whitespace trim|notrim +``` + +For example: + +``` +\whitespace trim +``` diff --git a/editions/tw5.com/tiddlers/pragmas/Pragma_ _widget.tid b/editions/tw5.com/tiddlers/pragmas/Pragma_ _widget.tid new file mode 100644 index 000000000..f8e589d4a --- /dev/null +++ b/editions/tw5.com/tiddlers/pragmas/Pragma_ _widget.tid @@ -0,0 +1,27 @@ +created: 20221009121950630 +modified: 20230419103154329 +tags: Pragmas +title: Pragma: \widget +type: text/vnd.tiddlywiki + +<<.from-version "5.3.0">> The ''\widget'' [[pragma|Pragmas]] is used to [[define custom widgets|Custom Widgets]]. It is a shortcut syntax for the SetVariableWidget with an implicit ParametersWidget. + +The usual form allows custom widgets to span multiple lines: + +``` +\widget ([:],[:]...) + +\end [] +``` + +Note that the `\end` marker can optionally specify the name of the widget to which it relates which allows widget definitions to be nested. + +There is also a single line form for shorter widgets: + +``` +\widget ([:],[:]...) +``` + +The first line of the definition specifies the widget name and any parameters. Each parameter has a name and, optionally, a default value that is used if no value is supplied on a particular call to the widget. The lines that follow contain the text of the widget text (i.e. the snippet represented by the widget name), until `\end` appears on a line by itself: + +See [[Custom Widgets]] for more details. \ No newline at end of file diff --git a/editions/tw5.com/tiddlers/pragmas/Pragmas.tid b/editions/tw5.com/tiddlers/pragmas/Pragmas.tid new file mode 100644 index 000000000..46981c51e --- /dev/null +++ b/editions/tw5.com/tiddlers/pragmas/Pragmas.tid @@ -0,0 +1,13 @@ +created: 20220917112416666 +modified: 20230419103154329 +tags: Concepts [[WikiText Parser Modes]] +title: Pragmas +type: text/vnd.tiddlywiki + +A <<.def pragma>> is a special component of WikiText that provides control over the way the remaining text is parsed. + +Pragmas occupy lines that start with `\`. They can only appear at the start of the text of a tiddler, but blank lines and comments are allowed between them. If a pragma appears in the main body of the text, it is treated as if it was ordinary text. + +The following pragmas are available: + +<> diff --git a/editions/tw5.com/tiddlers/procedures/Procedure Calls.tid b/editions/tw5.com/tiddlers/procedures/Procedure Calls.tid new file mode 100644 index 000000000..d66d8f274 --- /dev/null +++ b/editions/tw5.com/tiddlers/procedures/Procedure Calls.tid @@ -0,0 +1,56 @@ +caption: Macro Calls +created: 20221007130006705 +modified: 20230419103154329 +tags: WikiText Procedures +title: Procedure Calls +type: text/vnd.tiddlywiki + +!! Introduction + +This tiddler describes the different ways in which [[macros|Procedures]] can be called. + +!! Procedure Call Transclusion Shortcut + +To call a [[procedure|Procedures]], place `<<`double angle brackets`>>` around the name and any parameter values. + +``` +<> +``` + +By default, parameters are listed in the same order as in the procedure definition. A parameter can be labelled with its name and a colon to allow them to be listed in a different order. + +If no value is specified for a parameter, the default value given for that parameter in the [[procedure definition|Procedure Definitions]] is used instead. (If no default value was defined, the parameter is blank). + +Each parameter value can be enclosed in `'`single quotes`'`, `"`double quotes`"`, `"""`triple double quotes`"""` or `[[`double square brackets`]]`. Triple double quotes allow a value to contain almost anything. If a value contains no spaces or single or double quotes, it requires no delimiters. + +See the discussion about [[parser modes|WikiText parser mode: macro examples]] + +!! Procedure Calls with <<.wlink TranscludeWidget>> Widget + +The shortcut syntax expands to the <<.wlink TranscludeWidget>> widget with the `$variable` attribute specifying the name of the procedure to transclude. + +``` +<$transclude $variable="my-procedure" param="This is the parameter value"/> +``` + +The widget itself offers greater flexibility than the shortcut syntax, including the ability to specify dynamic parameter values. + +!! Assigning Procedure Calls to Attribute Values + +The text of a procedure can be directly assigned to an attribute of a widget or HTML element. The result of the procedure is not wikified, which means that [[parameter handling|Procedure Parameter Handling]] does not take place. + +``` +
>> +... +
+``` + +!! Using Procedure Calls in Filters + +Procedure calls can be used in filters. The text is not wikified which again means that the parameters will be ignored. + +``` +<$list filter="[]"> +... + +``` \ No newline at end of file diff --git a/editions/tw5.com/tiddlers/procedures/Procedure Definitions.tid b/editions/tw5.com/tiddlers/procedures/Procedure Definitions.tid new file mode 100644 index 000000000..e108f219d --- /dev/null +++ b/editions/tw5.com/tiddlers/procedures/Procedure Definitions.tid @@ -0,0 +1,43 @@ +created: 20221007125701001 +modified: 20230419103154329 +tags: WikiText Procedures +title: Procedure Definitions +type: text/vnd.tiddlywiki + +!! Introduction + +This tiddler describes the different ways in which [[macros|Procedures]] can be defined. + +!! Procedure Definition Pragma + +Macros are created using the [[Pragma: \procedure]] at the start of a tiddler. The definitions are available in the rest of the tiddler that defines them, plus any tiddlers that it transcludes. + +``` +\define my-procedure(param) +This is the macro text (param=<>) +\end +``` + +!! Procedure Definition with Set Widget + +Procedures are implemented as a special kind of [[variable|Variables]] and so internally are actually defined with a <<.wlink SetWidget>> widget. + +``` +<$set name="my-procedure" value="This is the procedure text"> +... + +``` + +<<.note """that it is not currently possible to specify parameters when defining a procedure with the <<.wlink SetWidget>> widget.""">> + +!! Importing Procedure Definitions + +The [[Pragma: \import]] or <<.wlink ImportVariablesWidget>> widget can be used to copy procedure definitions from another tiddler. + +!! `$:/tags/Macro` Tag + +Global procedures can be defined using the [[SystemTag: $:/tags/Macro]]. + +The tag [[SystemTag: $:/tags/Macro/View]] is used to define procedures that should only be available within the main view template and the preview panel. + +The tag [[SystemTag: $:/tags/Macro/View/Body]] is used to define procedures that should only be available within the main view template body and the preview panel. diff --git a/editions/tw5.com/tiddlers/procedures/Procedure Parameter Handling.tid b/editions/tw5.com/tiddlers/procedures/Procedure Parameter Handling.tid new file mode 100644 index 000000000..f4841e4e9 --- /dev/null +++ b/editions/tw5.com/tiddlers/procedures/Procedure Parameter Handling.tid @@ -0,0 +1,24 @@ +created: 20221007130538285 +modified: 20230419103154329 +tags: WikiText Procedures +title: Procedure Parameter Handling +type: text/vnd.tiddlywiki + +!! Introduction + +[[Procedure|Procedures]] parameters are made available as variables when the procedure contents are wikified. + +!! Accessing Parameters as Variables + +When procedures are wikified, the parameters can be accessed as variables. + +For example: + +<$macrocall $name="wikitext-example-without-html" src="""\procedure say-hi(name,address) +Hi, I'm <> and I live in <
>. +\end + +<> +"""/> + +Accessing parameters as variables only works in procedures that are wikified and not, for example, when a procedure is used as an attribute value. diff --git a/editions/tw5.com/tiddlers/procedures/Procedures.tid b/editions/tw5.com/tiddlers/procedures/Procedures.tid new file mode 100644 index 000000000..15b422647 --- /dev/null +++ b/editions/tw5.com/tiddlers/procedures/Procedures.tid @@ -0,0 +1,35 @@ +created: 20221007124007426 +modified: 20230419103154329 +tags: Concepts Reference +title: Procedures +type: text/vnd.tiddlywiki + +!! Introduction + +<<.from-version "5.3.0">> A <<.def procedure>> is a named snippet of text. They are typically defined with the [[Pragma: \procedure]]: + +``` +\procedure my-procedure(parameter:"Default value") +This is the procedure, and the parameter is <>. +\end +``` + +The name wrapped in double angled [[brackets|Brackets]] is used a shorthand way of [[transcluding|Transclusion]] the snippet. Each of these <<.def "procedure calls">> can supply a different set of parameters: + +``` +<> +<> +``` + +The parameters that are specified in the procedure call are made available as variables. + +!! How Procedures Work + +Procedures are implemented as a special kind of [[variable|Variables]]. The only thing that distinguishes them from ordinary variables is the way that the parameters are handled. + +!! Using Procedures + +* [[Procedure Definitions]] describes how to create procedures +* [[Procedure Calls]] describes how to use procedures +* [[Procedure Parameter Handling]] describes how procedure parameters work + diff --git a/editions/tw5.com/tiddlers/variables/Variable Usage.tid b/editions/tw5.com/tiddlers/variables/Variable Usage.tid new file mode 100644 index 000000000..2166f206a --- /dev/null +++ b/editions/tw5.com/tiddlers/variables/Variable Usage.tid @@ -0,0 +1,154 @@ +created: 20230421020225031 +modified: 20230422144812613 +tags: +title: Variable Usage +type: text/vnd.tiddlywiki + +\define m1(a1) $a1$ - <<__a1__>> - <> +\procedure p1(a1) $a1$ - <<__a1__>> - <> +\function f1(a1) "$a1$" "-" [<__a1__>] ="-" [] :and[join[ ]] + +!Ways to define variables and parameters +|! how declared|! how parameters are defined|! accessing parameter values in the body| +|\define|`()`|`$param$, <<__param__>>`| +|~|<<.wlink ParametersWidget>> or `\parameters`|`<>`| +|<<.wlink SetWidget>>, <<.wlink LetWidget>>, <<.wlink VarsWidget>>|<<.wlink ParametersWidget>> or `\parameters`|`<>`| +|\procedure, \widget|`()`, <<.wlink ParametersWidget>> or `\parameters`|`<>`| +|\function|`()`|``| +|javascript macros|`exports.params` javascript property array|passed as normal javascript function parameter and so accessed as a normal javascript variable| + +!!Examples +These examples are meant to provide insight into the various ways of defining and using parameters. In many cases they do not illustrate best practices. + +!!! \define + +<$let eg='\define mp1(a1) $a1$ - <<__a1__>> + +\define mp2() <$parameters a1><> + +\define mp3() +\parameters(a1) +<> +\end + +|<>|<>|<>| +'> +<$macrocall $name="copy-to-clipboard-above-right" src=<>/> +<$codeblock code=<>/> + + +!!! $set, $let, $vars + +<$let eg='<$set name="sp1" value="<$parameters a1><>"> +<$set name="sp2" value=""" +\parameters(a1) +<$parameters a1><> +"""> +<$vars vp1="<$parameters a1><>" vp2=""" +\parameters(a1) +<$parameters a1><> +"""> +<$let lp1="<$parameters a1><>" lp2=""" +\parameters(a1) +<$parameters a1><> +"""> + +|<>|<>| +|<>|<>| +|<>|<>| + + + + +'> +<$macrocall $name="copy-to-clipboard-above-right" src=<>/> +<$codeblock code=<>/> + + +!!! \procedure, \widget + +<$let eg='\procedure pp1(a1) <> + +\procedure pp2() <$parameters a1><> + +\procedure pp3() +\parameters(a1) +<> +\end + +\procedure wp1(a1) <> + +\widget wp2() <$parameters a1><> + +\widget wp3() +\parameters(a1) +<> +\end + +|<>|<>|<>| +|<>|<>|<>| +'> +<$macrocall $name="copy-to-clipboard-above-right" src=<>/> +<$codeblock code=<>/> + + +!!! \function +<$let eg='\function fp1(a1) [] +|<>|'> +<$macrocall $name="copy-to-clipboard-above-right" src=<>/> +<$codeblock code=<>/> + + + +!Behavior of invoked variables depends on how the variable was declared + +|!how invoked|!how declared|!behavior| +|`<$transclude $variable=macro/>` or `<>` in normal wikitext context|\define|All wikitext and variable substitution and textual substitution takes place| +|~|<<.wlink SetWidget>>, <<.wlink LetWidget>>, <<.wlink VarsWidget>>, \procedure, \widget|All wikitext and variable substitution takes place| +|~|\function|Invoking a function in this way (`<>`) is a synonym for `<$text text={{{[function[macro]]}}}/>`. As with any filtered transclusion (i.e. triple curly braces), all results except the first are discarded.| +|||| +|widget attribute: `
>/>`|\define|Textual substitution of parameters is performed on the body text. No further processing takes place. The result after textual substitution is used as the attribute's value| +|~|<<.wlink SetWidget>>, <<.wlink LetWidget>>, <<.wlink VarsWidget>>, \procedure, \widget|Body text is retrieved as-is and used as the attribute's value.| +|~|\function|When a function is invoked as `
>/>`, it is a synonym for `
`. As with any filtered transclusion (i.e. triple curly braces), all results except the first are discarded. That first result is used as the attribute's value. Note that functions are recursively processed even when invoked in this form. In other words a filter expression in a function can invoke another function and the processing will continue| +|||| +|filter operator parameter: `[]`|\define|Textual substitution of parameters is performed on the body text. No further processing takes place. The result after textual substitution is used as the filter operator's parameter.| +|~|<<.wlink SetWidget>>, <<.wlink LetWidget>>, <<.wlink VarsWidget>>, \procedure, \widget|Body text is retrieved as-is and used as the filter operator's parameter.| +|~|\function|The body text of the function is treated as a filter expression and evaluated. The first result is passed to the operator as a parameter. The remaining results are discarded| +|||| +|function call in a filter expression: `[function[macro]]`|\define, <<.wlink SetWidget>>, <<.wlink LetWidget>>, <<.wlink VarsWidget>>, \procedure, \widget|Every function is a variable, but only variables defined using \function are invokable using the <<.olink function>> filter operator. Attempts to use a non-function variable is the same as if the function doesn't exist. The behavior in this case is like the identity function. All filter input is passed unchanged to the output.| +|~|\function|The body text of the function is treated as a filter expression and evaluated. This filter expression can itself contain a function call. Filter expressions can be factored out into functions arbitrarily deep.| + +!! Examples + +Below is an example macro, procedure and function definition. All three forms of parameter substitution `$a1$`, `<<__a1__>>`, and `<>` are included in each definition. The output helps illustrate when each form of substitution will or will not have affect. + +``` +\define m1(a1) $a1$ - <<__a1__>> - <> +\procedure p1(a1) $a1$ - <<__a1__>> - <> +\function f1(a1) $a1$ "-" [<__a1__>] ="-" [] :and[join[ ]] +``` + +| !Variable transclusion|!output | +| `<>`|<>| +| `<>`|<>| +| `<>`|<>| +| !Widget attribute|!output | +| `<$text text=<>/>`|<$text text=<>/>| +| `<$text text=<>/>`|<$text text=<>/>| +| `<$text text=<>/>`|<$text text=<>/>| +| !Filter operator parameter|!output | +| `[]`|<$text text={{{[]}}}/>| +| `[]`|<$text text={{{[]}}}/>| +| `[]`|<$text text={{{[]}}}/>| +| !Function call in filter expression|!output | +| `[function[m1],[foo]]`|<$text text={{{[function[m1],[foo]]}}}/>| +| `[function[p1],[foo]]`|<$text text={{{[function[p1],[foo]]}}}/>| +| `[function[f1],[foo]]`|<$text text={{{[function[f1],[foo]]}}}/>| + +!Namespaces + +*''tiddler titles'' - tiddlers are uniquely identified by their title. The namespace for tiddler titles and variable names are completely separate. +*''variables'' - \define, <<.wlink SetWidget>>, <<.wlink LetWidget>>, <<.wlink VarsWidget>>, \procedure, \widget, \function all create variables. If the same name is used, then later define will overwrite earlier defined + *''<<.op function>> filter operator parameter'' - only variables defined using \function can be called using the <<.olink function>> operator + *''filter operators'' - only the [[javascript defined filter operators|Filter Operators]] and variables defined using \function with name starting with a dot can be called + *''widgets'' - variables defined using \widget can be invoked using `<$widget/>` syntax ONLY if the name starts a dollar sign (to override existing javascript defined widgets) or double dollar sign (to define [[custom widgets|Custom Widgets]]). Without the dollar sign prefix, defining variables using \widget is no different than using \procedure. diff --git a/editions/tw5.com/tiddlers/variables/Variables.tid b/editions/tw5.com/tiddlers/variables/Variables.tid index 2e80f2678..65ad96b31 100644 --- a/editions/tw5.com/tiddlers/variables/Variables.tid +++ b/editions/tw5.com/tiddlers/variables/Variables.tid @@ -1,23 +1,142 @@ created: 20141002133113496 -modified: 20221221175615776 -tags: Concepts Reference +modified: 20230422150445336 +tags: Concepts Reference WikiText title: Variables type: text/vnd.tiddlywiki -A <<.def variable>> is a snippet of text that can be accessed by name within a particular branch of the [[widget tree|Widgets]]. The snippet is known as the variable's <<.def value>>. +!! Introduction -A new variable is defined using a <<.wlink SetWidget>> or <<.wlink LetWidget>> widget, and is then available to any of the children of that widget, including transcluded content. A <<.wid set>> widget can reuse an existing name, thus binding a different snippet to that name for the duration of the widget's children. +A <<.def variable>> is a snippet of text that can be accessed by name. The text is referred to as the variable's <<.def value>>. -The <<.wlink ListWidget>> widget by default sets a particular variable <<.var currentTiddler>> to each listed title in turn. +Variables are defined by [[widgets|Widgets]]. Several core widgets define variables, the most common being the <<.wlink SetWidget>>, <<.wlink LetWidget>> and <<.wlink ListWidget>> widgets. -For an overview of how to use variables, see [[Variables in WikiText]]. +The values of variables are available to descendant widgets, including transcluded content. For example, within each tiddler in the main story river the variable "currentTiddler" is set to the title of the tiddler. -Despite the term <<.word variable>>, ''each snippet is a constant string''. The apparent variability is actually the result of the presence of multiple variables with the same name in different parts of the widget tree. +Variables can also be overwritten by descendent widgets defining variables of the same name, thus binding a different snippet to that name for the scope of the children of the widget. -[[Macros]] are a special form of variable whose value can contain placeholders that get filled in with parameters whenever the macro is used. +!! Special Kinds of Variables -By themselves, the snippets are <<.em not>> parsed as WikiText. However, a variable reference will transclude a snippet into a context where ~WikiText parsing <<.em may>> be occurring. Within a snippet, the only markup detected is `$name$` for a macro parameter transclusion and `$(name)$` for a variable transclusion. +There are several special kinds of variable that extend their basic capabilities: -The <<.mlink dumpvariables>> macro lists all variables (including macros) that are available at that position in the widget tree. +* [[Procedures]] are snippets of text that can be passed parameters when wikified +* [[Functions]] are snippets of text containing [[filters|Filters]] with optional named parameters +* [[Custom Widgets]] are snippets of text containing definitions of custom [[widget|Widgets]] +* [[Macros]] are snippets of text that can contain placeholders that are filled in with parameters whenever the macro is used + +Note that these special kinds of variable can only be created with the associated shortcut definition syntax. + +For a more detailed comparison of these special kinds of variables, see [[Variable Usage]]. + +!! Defining Variables + +The following core widgets are commonly used to define variables: + +* <<.wlink LetWidget>> widget -- the easiest way to define multiple variables +* <<.wlink SetWidget>> widget -- the most flexible way to define a single variable +* <<.wlink ParametersWidget>> widget -- used to declare parameter variables within [[procedures|Procedures]] and [[custom widgets|Custom Widgets]] +* <<.wlink ListWidget>> widget -- defines a loop variable and optional counter variable +* <<.wlink SetMultipleVariablesWidget>> widget -- allows creation of multiple variables at once where the names and values are not known in advance + +!! Using Variables + +Once a variable is defined there are several ways to access it. + +!!! Transcluding Variables + +Transcluding a variable renders the text contents of the variable as if it replaced the call. It is a shortcut syntax for the <<.wlink TranscludeWidget>> widget with the `$variable` attribute. + +``` +<> +``` + +Parameters can be passed to the transclusion as follows: + +``` +<> +<> +<> +``` + +The handling of these parameters depends on the kind of variable: + +* [[Procedures]] assign the parameters to variables that are available within the procedure +* [[Macros]] replace the text of the special markers `$param$` with the values passed to the macro for those parameters (see [[Macro Parameter Handling]] for the details) + +The parameters are ignored for other kinds of variable. + +!!! Macro Variable Substitutions + +Before the text of a macro is used, the special markers `$(variable)$` are replaced with the values of the named variable. + +!!! Variable Attributes + +Variables can be used as the value of attributes of widgets or HTML elements: + +``` +
>> +``` + +Parameters can be passed: + +``` +
>> +... +
>> +... +
>> +... +``` + +The handling of these parameters depends on the kind of variable: + +* [[Functions]] assign the parameters to variables that are available within the function +* [[Macros]] replace the text of the special markers `$param$` with the values passed to the macro for those parameters (see [[Macro Parameter Handling]] for the details) + +The parameters are ignored for other kinds of variable. + +!!! Variables in Filters + +Variables can be accessed within [[Filters]] using angle brackets to quote the name: + +``` +[] +``` + +Parameters can be passed in the usual way: + +``` +[] +[] +[] +... +``` + +!! See Also + +* The <<.mlink dumpvariables>> macro lists all variables that are available at that position in the widget tree +* Complete listing of ~TiddlyWiki's built-in [[Core Variables]] + +!! Examples + +!!! Example of Defining a Variable + +<$macrocall $name=".example" n="1" +eg="""<$set name=animal value=zebra> +<> +"""/> + +!!! Example of Defining a Macro + +The `\define` pragma below [[defines a macro|Macro Definitions]] called <<.var tags-of-current-tiddler>>. The macro returns the value of the tiddler's <<.field tags>> field, and can be accessed from anywhere else in the same tiddler (or in any tiddler that [[imports|ImportVariablesWidget]] it). + +<$importvariables filter="$:/editions/tw5.com/macro-examples/tags-of-current-tiddler"> +<$codeblock code={{$:/editions/tw5.com/macro-examples/tags-of-current-tiddler}}/> +<$macrocall $name=".example" n="2" eg="""The tags are: <>"""/> + + +!!! Example of Using a Variable as a Filter Parameter + +This example uses the <<.olink backlinks>> [[operator|Filter Operators]] to list all tiddlers that link to this one. + +<$macrocall $name=".example" n="3" eg="""<backlinks[]]">>"""/> -~TiddlyWiki's core has [[several variables|Core Variables]] built in. diff --git a/editions/tw5.com/tiddlers/widgets/Custom Widgets.tid b/editions/tw5.com/tiddlers/widgets/Custom Widgets.tid new file mode 100644 index 000000000..c220302cf --- /dev/null +++ b/editions/tw5.com/tiddlers/widgets/Custom Widgets.tid @@ -0,0 +1,84 @@ +created: 20221007144237585 +modified: 20230419103154328 +tags: Concepts Reference +title: Custom Widgets +type: text/vnd.tiddlywiki + +!! Introduction + +<<.from-version "5.3.0">> A <<.def "custom widget">> is a special kind of [[procedure|Procedures]] that can be called using the same syntax as widgets. + +Custom widgets can also be used to override built-in JavaScript widgets to customise their behaviour. + +!! Defining Custom Widgets + +Custom widgets are usually defined with the [[Pragma: \widget]]: + +``` +\widget $$my-widget(attribute:"Default value") +This is the widget, and the attribute is <>. +\end +``` + +The name of the widget must start with one or two dollar signs: + +* A ''single dollar sign'' is used to override existing core widgets +** for example, `$text` or `$codeblock` +* ''Double dollar signs'' are used to define a custom widget +** for example, `$$mywidget` or `$$acme-logger` + +!! Using Custom Widgets + +Custom widgets are called in the same way as ordinary built-in widgets: + +``` +<$my-widget/> + +<$my-widget attribute="The parameter"/> +``` + +The attributes that are specified in the widget call are made available as parameter variables. + +!! Accessing Content of Custom Widgets + +Within the definition of a custom widget the content of the calling widget is available via the `<$slot $name="ts-raw"/>` widget. The contents of the <<.wlink SlotWidget>> widget is used as the default content if the widget was called without any content. + +For example: + +<>/> +<$slot $name="ts-raw"> + Whale + +\end + +<$$mywidget one="Dingo"> + Crocodile + + +<$$mywidget/>""">> + +!! How Custom Widgets Work + +Custom widgets are implemented as a special kind of [[variable|Variables]]. The only thing that distinguishes them from ordinary variables is the way that they can be called as a custom widget with attributes mapped to parameters. + +!! Overriding Core ~JavaScript Widgets + +Custom widgets can use the <<.wlink "GenesisWidget">> widget to invoke the original widget, bypassing the override. For example, here we override the <<.wlink CodeBlockWidget>> widget to add `≤≥` symbols around each string of text. + + +<addprefix[≤]addsuffix[≥]] }}}/> +\end + +<$codeblock code="Kangaroo"/> + +<$codeblock code={{$:/SiteTitle}}/> + +``` +Python +``` + +<$let test="Tiger"> +<$codeblock code=<>/> +""">> diff --git a/editions/tw5.com/tiddlers/widgets/ErrorWidget.tid b/editions/tw5.com/tiddlers/widgets/ErrorWidget.tid index aee5617d2..d6afb86ed 100644 --- a/editions/tw5.com/tiddlers/widgets/ErrorWidget.tid +++ b/editions/tw5.com/tiddlers/widgets/ErrorWidget.tid @@ -1,6 +1,6 @@ caption: error created: 20220909111836951 -modified: 20220909111836951 +modified: 20230419103154328 tags: Widgets title: ErrorWidget type: text/vnd.tiddlywiki diff --git a/editions/tw5.com/tiddlers/widgets/FillWidget.tid b/editions/tw5.com/tiddlers/widgets/FillWidget.tid new file mode 100644 index 000000000..3fffd51f0 --- /dev/null +++ b/editions/tw5.com/tiddlers/widgets/FillWidget.tid @@ -0,0 +1,21 @@ +caption: fill +created: 20220909111836951 +modified: 20230419103154328 +tags: Widgets +title: FillWidget +type: text/vnd.tiddlywiki + +! Introduction + +<<.from-version "5.3.0">> The <<.wlink FillWidget>> widget is used within a <<.wlink TranscludeWidget>> widget to specify the content that should be copied to the named "slot". Slots are defined by the <<.wlink SlotWidget>> widget within the transcluded content. + +See the <<.wlink TranscludeWidget>> widget for details. + +! Attributes + +The content of the <<.wlink FillWidget>> widget is used as the content to be passed to the transclusion. + +|!Attribute |!Description | +|$name |The name of the slot to be filled | + +<<.warning """The $name attribute must be specified as a literal string""">> diff --git a/editions/tw5.com/tiddlers/widgets/ImportVariablesWidget.tid b/editions/tw5.com/tiddlers/widgets/ImportVariablesWidget.tid index a9451bc63..93ae44ae4 100644 --- a/editions/tw5.com/tiddlers/widgets/ImportVariablesWidget.tid +++ b/editions/tw5.com/tiddlers/widgets/ImportVariablesWidget.tid @@ -34,7 +34,7 @@ So-called global macros are implemented within the main page template ([[$:/core ! `\import` Pragma -<<.from-version "5.1.18">> The `\import` [[pragma|Pragma]] is an alternative syntax for using the ImportVariablesWidget. For example, the previous example could be expressed as: +<<.from-version "5.1.18">> The [[Pragma: \import]] is an alternative syntax for using the ImportVariablesWidget. For example, the previous example could be expressed as: ``` \import [[$:/core/ui/PageMacros]] [all[shadows+tiddlers]tag[$:/tags/Macro]!has[draft.of]] diff --git a/editions/tw5.com/tiddlers/widgets/MacroCallWidget.tid b/editions/tw5.com/tiddlers/widgets/MacroCallWidget.tid index e163c1d41..e06e3601d 100644 --- a/editions/tw5.com/tiddlers/widgets/MacroCallWidget.tid +++ b/editions/tw5.com/tiddlers/widgets/MacroCallWidget.tid @@ -1,48 +1,31 @@ caption: macrocall created: 20131024141900000 -modified: 20220122193731433 -tags: Widgets +modified: 20230419103154328 +tags: Widgets $:/deprecated title: MacroCallWidget type: text/vnd.tiddlywiki -! Introduction +<<.deprecated-since "5.3.0" "TranscludeWidget">> -The macro call widget provides a more flexible alternative syntax for invoking macros compared to the usual `<>` syntax documented in [[Macros in WikiText]]. +The <<.wlink MacroCallWidget>> widget is deprecated. While it will continue to work, users are now advised to use the <<.wlink TranscludeWidget>> widget, converting the `$name` attribute to `$variable`. -For example, a macro called `italicise` that takes a single parameter called `text` would usually be invoked like this: +For example, ``` -<> -<> +<$macrocall $name="my-macro" my-parameter="Elephant"/> ``` -The same macro can be invoked using the macro call widget like this: +should be changed to: ``` -<$macrocall $name="italicise" text="Text to be made into italics"/> -<$macrocall $name="italicise" text={{Title of tiddler containing text to be italicised}}/> -<$macrocall $name="italicise" text=<>/> +<$transclude $variable="my-macro" my-parameter="Elephant"/> ``` -The advantages of the widget formulation are: - -* Macro parameters are specified as widget attributes, thus allowing indirection via `{{title!!field}}`, `<>` or `{{{filter}}}` -* The output format can be chosen from several options: -** `text/html` wikifies the result of the macro -** `text/plain` wikifies the result of the macro and then extracts the plain text characters (ie. ignoring HTML tags) -** <<.from-version "5.1.23">> `text/raw` returns the result of the macro, without wikification - -You can see several examples of the macro call widget within the core: - -* Listing module information: [[$:/snippets/modules]] -* Listing field information: [[$:/snippets/allfields]] -* Generating `data:` URIs: [[$:/themes/tiddlywiki/starlight/styles.tid]] - -See also [[WikiText parser mode: macro examples]] +Internally, the <<.wlink MacroCallWidget>> widget is implemented via the <<.wlink TranscludeWidget>> widget. ! Content and Attributes -The content of the `<$macrocall>` widget is ignored. +The content of the <<.wlink MacroCallWidget>> widget is ignored. |!Attribute |!Description | |$name |Name of the macro to invoke | diff --git a/editions/tw5.com/tiddlers/widgets/ParametersWidget.tid b/editions/tw5.com/tiddlers/widgets/ParametersWidget.tid new file mode 100644 index 000000000..8ddee3151 --- /dev/null +++ b/editions/tw5.com/tiddlers/widgets/ParametersWidget.tid @@ -0,0 +1,61 @@ +caption: parameters +created: 20220909111836951 +modified: 20230419103154328 +tags: Widgets +title: ParametersWidget +type: text/vnd.tiddlywiki + +<<.from-version "5.3.0">> The <<.wlink ParametersWidget>> widget is used within transcluded content to declare the parameters to be made available to the <<.wlink TranscludeWidget>> widget. + +There are shortcuts for common scenarios that can often make it unnecessary to use the <<.wlink ParametersWidget>> widget directly: + +* the [[Pragma: \parameters]] +* the [[Pragma: \procedure]] for declaring procedure +* the [[Pragma: \widget]] for declaring custom widgets + +The <<.wlink ParametersWidget>> widget must be used directly in the following situations: + +* When the default value of a parameter must be computed dynamically +* When the `$depth` attribute is used to retrieve parameters from a parent transclusion (see below) + +! Content and Attributes + +The content of the <<.wlink ParametersWidget>> widget is the scope within which the values of the parameters can be accessed as ordinary variables. + +|!Attribute |!Description | +|$depth |The index of the parent transclusion from which to obtain the parameters (defaults to 1). See below | +|$parseMode |Optional name of a variable in which is made available the parse mode of the content of the parent transclusion (the parse mode can be "inline" or "block") | +|$parseTreeNodes |Optional name of a variable in which is made available the JSON representation of the parse tree nodes contained within the parent transclusion | +|$slotFillParseTreeNodes |Optional name of a variable in which is made available the JSON representation of the parse tree nodes corresponding to each fill widget contained within the parent transclusion (as an object where the keys are the slot names and the values are the parse tree nodes) | +|$params |Optional name of a variable in which is made available the JSON representation of the parameters passed to the parent transclusion (as an object where the keys are the parameter names and the values are the coresponding values) | +|//{attributes not starting with $}// |Any attributes that do not start with a dollar are used as parameters, with the value specifying the default to be used for missing parameters | +|//{other attributes starting with $}// |Other attributes starting with a single dollar sign are reserved for future use | +|//{attributes starting with $$}// |Attributes starting with two dollar signs are used as parameters to the transclusion, but with the name changed to use a single dollar sign. The value specifies the default to be used for missing parameters | + +<<.note "Note the special treatment required for parameters names that start with a `$`; this can be avoided by using one of the pragmas">> + +!! `$depth` Attribute + +By default, the <<.wlink ParametersWidget>> widget retrieves parameters from the immediate parent transclusion. The `$depth` attribute permits access to the parameters of parent transclusions by specifying an index to the parent to be inspected ("1" is the immediate parent, "2" is the parent of that parent, etc.). This is useful in some situations where an intervening transclusion prevents immediate access to desired parameters. + +!! `$parseMode`, `$parseTreeNodes`, `$slotFillParseTreeNodes` and `$params` Attributes + +These attributes provide low level access to the contents of the transcluding widget: + +* The `$params` attribute provides access to the raw parameters provided to the transcluding widget. Represented in JSON as an object with keys of the parameter names and values of the corresponding parameter values +* The `$parseMode` attribute contains `block` or `inline` to indicate whether the contents was parsed in block or inline mode +* The `$parseTreeNodes` attribute provides access to the raw parse tree nodes that represent the contents of the transcluding widget. Represented in JSON as an array of parse tree nodes +* The `$slotFillParseTreeNodes` attribute provides access to the raw parse tree nodes corresponding to the filled slots within the contents of the transcluding widget. Represented in JSON as an object with keys of the slot name and values being an array of parse tree nodes + +! Examples + +Here the <<.wlink ParametersWidget>> widget is used to declare a parameter whose default value is transcluded from another tiddler. + +<$macrocall $name='wikitext-example-without-html' +src="""\procedure mymacro() +<$parameters name={{$:/SiteTitle}} age="21"> +My name is <> and my age is <>. + +\end + +<$transclude $variable="mymacro" age="19"/>"""/> diff --git a/editions/tw5.com/tiddlers/widgets/SlotWidget.tid b/editions/tw5.com/tiddlers/widgets/SlotWidget.tid new file mode 100644 index 000000000..f7b26e62d --- /dev/null +++ b/editions/tw5.com/tiddlers/widgets/SlotWidget.tid @@ -0,0 +1,19 @@ +caption: slot +created: 20220909111836951 +modified: 20230419103154329 +tags: Widgets +title: SlotWidget +type: text/vnd.tiddlywiki + +! Introduction + +<<.from-version "5.3.0">> The <<.wlink SlotWidget>> widget is used within transcluded content to mark "slots" that the transcluding widget can fill with the <<.wlink FillWidget>> widget. + +See the <<.wlink TranscludeWidget>> widget for details. + +! Attributes + +The content of the <<.wlink SlotWidget>> widget is used as a fallback for the slot content if the corresponding <<.wlink FillWidget>> widget is not found. + +|!Attribute |!Description | +|$name |The name of the slot being defined | diff --git a/editions/tw5.com/tiddlers/widgets/TranscludeWidget.tid b/editions/tw5.com/tiddlers/widgets/TranscludeWidget.tid index 6bc507cae..348de1090 100644 --- a/editions/tw5.com/tiddlers/widgets/TranscludeWidget.tid +++ b/editions/tw5.com/tiddlers/widgets/TranscludeWidget.tid @@ -1,24 +1,178 @@ caption: transclude created: 20130824142500000 -modified: 20220513114759336 +modified: 20230419103154329 tags: Widgets title: TranscludeWidget type: text/vnd.tiddlywiki ! Introduction -The TranscludeWidget dynamically imports content from another tiddler. +The <<.wlink TranscludeWidget>> widget dynamically includes the content from another tiddler or variable, rendering it as if the transclude widget were replaced by the target content. + +The <<.wlink TranscludeWidget>> widget can be used to render content of any type: wikitext, images, videos, etc. + +Transclusion is the underlying mechanism for many higher level wikitext features, such as procedures, custom widgets and macros. + +! Example + +Here is a complete example showing the important features of the <<.wlink TranscludeWidget>> widget: + +``` +\procedure mymacro(name,age) +My name is <> and my age is <>. +\end + +<$transclude $variable="mymacro" name="James" age="19"/> +``` + +* `\procedure` defines a variable as a procedure with two parameters, ''name'' and ''age'' +* The content of the procedure refers to the parameters as variables +* The <<.wlink TranscludeWidget>> widget specifies the variable to transclude, and values for the parameters. + +! Legacy vs. Modern Mode + +The <<.wlink TranscludeWidget>> widget can be used in two modes: + +* <<.from-version "5.3.0">> ''Modern mode'' offers the full capabilities of the <<.wlink TranscludeWidget>> widget, and incorporates the functionality of the <<.wlink MacroCallWidget>> widget. It is indicated by the presence of at least one attribute starting with a dollar sign `$` +* ''Legacy mode'' offers a more limited set of capabilities. It is indicated by the absence of any attributes starting with a dollar sign `$` + +Modern mode is recommended for use in new applications. ! Attributes -|!Attribute |!Description | -|tiddler |The title of the tiddler to transclude (defaults to the current tiddler) | -|field |The field name of the current tiddler (defaults to "text"; if present takes precedence over the index attribute) | -|index |The index of a property in a [[DataTiddler|DataTiddlers]] | -|subtiddler |Optional SubTiddler title when the target tiddler is a [[plugin|Plugins]] (see below) | -|mode |Override the default parsing mode for the transcluded text to "block" or "inline" | +| !Attribute |<| !Description | +| !(modern) | !(legacy) |~| +|$variable |- |Name of the variable to transclude | +|$tiddler |tiddler |The title of the tiddler to transclude (defaults to the current tiddler) | +|$field |field |The field name of the current tiddler (defaults to "text"; if present takes precedence over the index attribute) | +|$index |index |The index of a property in a [[DataTiddler|DataTiddlers]] | +|$subtiddler |subtiddler |Optional SubTiddler title when the target tiddler is a [[plugin|Plugins]] (see below) | +|$mode |mode |Override the default parsing mode for the transcluded text to "block" or "inline" | +|$type |– |Optional ContentType used when transcluding variables, indexes or fields other than the ''text'' field| +|$output |- |ContentType for the output rendering (defaults to `text/html`, can also be `text/plain` or `text/raw`) | +|$recursionMarker |recursionMarker |Set to ''no'' to prevent creation of [[Legacy Transclusion Recursion Marker]] (defaults to ''yes'') | +|//{attributes not starting with $}// |– |Any other attributes that do not start with a dollar are used as parameters to the transclusion | +|//{other attributes starting with $}// |– |Other attributes starting with a single dollar sign are reserved for future use | +|//{attributes starting with $$}// |– |Attributes starting with two dollar signs are used as parameters to the transclusion, but with the name changed to use a single dollar sign | -The TranscludeWidget treats any contained content as a fallback if the target of the transclusion is not defined (ie a missing tiddler or a missing field). +! Basic Operation + +The basic operation of the <<.wlink TranscludeWidget>> widget is as follows: + +|`<$transclude/>` |Transcludes the text field of the current tiddler | +|`<$transclude $variable="alpha"/>` |Transcludes the variable "alpha" (note that procedures, custom widgets and macros are all special types of variable) | +|`<$transclude $tiddler="foo"/>` |Transcludes the text field of the tiddler "foo" | +|`<$transclude $field="bar"/>` |Transcludes the field "bar" of the current tiddler | +|`<$transclude $index="beta"/>` |Transcludes the index "beta" of the current tiddler | +|`<$transclude $tiddler="foo" $index="beta"/>` |Transcludes the index "beta" of the tiddler "foo" | + +! Transclusion Parameters + +Named string parameters can be passed to the <<.wlink TranscludeWidget>> widget. They are made available as variables within the transcluded text. Parameters are only supported in modern mode. + +When invoking a transclusion, parameters are specified as additional attributes that do not start with a dollar sign `$`: + +``` +<$transclude $tiddler="MyTiddler" firstParameter="One" secondParameter="Two"/> +``` + +To pass parameters whose names start with a dollar sign `$`, prefix them with an extra `$`. For example, to pass a parameter called `$tiddler`: + +``` +<$transclude $tiddler="MyTiddler" $$tiddler="One"/> +``` + +There are several different ways to declare parameters within a transclusion: + +* the <<.wlink ParametersWidget>> widget +* the [[Pragma: \parameters]] +* the [[Pragma: \procedure]] for declaring procedure +* the [[Pragma: \widget]] for declaring custom widgets +* the [[Pragma: \define]] for declaring macros + +An example of declaring parameters with the <<.wlink ParametersWidget>> widget: + +``` +<$parameters firstParameter="default" secondParameter="another default"> + Parameters are available here as the variables <> and <>. + +``` + +The [[Pragma: \parameters]] can be used as a shortcut syntax for declaring parameters. For example: + +``` +\parameters (firstParameter:"default",secondParameter:"another default") +Parameters are available here as the variables <> and <>. +``` + +! Transclusion Slots + +Transcluded content can define special named locations called slots. At the point of transclusion, blocks of wikitext can be passed to the <<.wlink TranscludeWidget>> widget to fill those slots. + +Slots work very similarly to parameters except that they can contain structured wikitext, and not just plain text. The primary advantage of slots over parameters is that the contents do not need to be wrapped in quotation symbols, making it much simpler to pass complex structures. + +For example, here we transclude the tiddler "Example" while using the <<.wlink FillWidget>> widget to pass wikitext blocks to fill the slots called "positive" and "negative": + +``` +<$transclude $tiddler="Example"> + <$fill $name="positive"> +

This is positive

+ + <$fill $name="negative"> +

This is negative

+ + +``` + +The tiddler "Example" uses the <<.wlink SlotWidget>> widget to specify the slots to be filled: + +``` +
    +
  1. <$slot $name="positive"/>
  2. +
  3. <$slot $name="negative"/>
  4. +
+``` + +The output will be equivalent to: + +``` +
    +
  1. +

    This is positive

    +
  2. +
  3. +

    This is negative

    +
  4. +
+``` + + +! Missing Transclusion Targets + +The TranscludeWidget uses the special slot `ts-missing` to specify the content to be rendered if the transclusion target is not defined (i.e. a missing tiddler or a missing field). + +For example: + +``` +<$transclude $tiddler="MissingTiddler"> +<$fill $name="ts-missing"> +This content is displayed if `MissingTiddler` is missing. + +<$fill $name="other"> +This content is passed to the transclusion as the slot value `other` + + +``` + +If no slots values are specified within the <<.wlink TranscludeWidget>> widget then the entire content of the widget is used as the missing content. + +For example: + +``` +<$transclude $tiddler="MissingTiddler"> +This content is displayed if `MissingTiddler` is missing. + +``` ! Parsing modes diff --git a/editions/tw5.com/tiddlers/wikitext/HTML in WikiText.tid b/editions/tw5.com/tiddlers/wikitext/HTML in WikiText.tid index d000cd975..ef42f948a 100644 --- a/editions/tw5.com/tiddlers/wikitext/HTML in WikiText.tid +++ b/editions/tw5.com/tiddlers/wikitext/HTML in WikiText.tid @@ -62,7 +62,7 @@ In an extension of conventional HTML syntax, attributes of elements/widgets can * a literal string * a transclusion of a TextReference -* a transclusion of a [[macro/variable|Macros in WikiText]] +* a transclusion of a [[macro/variable|Macros]] * as the result of a [[Filter Expression]] !! Style Attributes @@ -125,7 +125,7 @@ attr={{tiddler!!field}} !! Variable Attribute Values -Variable attribute values are indicated with double angle brackets around a [[macro invocation|Macro Calls in WikiText]]. For example: +Variable attribute values are indicated with double angle brackets around a [[macro invocation|Macro Calls]]. For example: ```
>> diff --git a/editions/tw5.com/tiddlers/wikitext/Macro Calls in WikiText.tid b/editions/tw5.com/tiddlers/wikitext/Macro Calls in WikiText.tid index b79d98134..0d45612f0 100644 --- a/editions/tw5.com/tiddlers/wikitext/Macro Calls in WikiText.tid +++ b/editions/tw5.com/tiddlers/wikitext/Macro Calls in WikiText.tid @@ -1,26 +1,8 @@ caption: Macro Calls -created: 20150220182252000 -modified: 20220122193853161 -tags: WikiText +created: 20220917074831994 +modified: 20220917074844235 +tags: title: Macro Calls in WikiText type: text/vnd.tiddlywiki -To call a [[macro|Macros]], place `<<`double angle brackets`>>` around the name and any parameter values. - -By default, parameters are listed in the same order as in the macro's definition. A parameter can be labelled with its name, either for clarity or to modify the order. - -If no value is specified for a parameter, the default value given for that parameter in the macro's definition is used instead. (If no default value was defined, the parameter is simply blank.) - -Each parameter value can be enclosed in `'`single quotes`'`, `"`double quotes`"`, `"""`triple double quotes`"""` or `[[`double square brackets`]]`. Triple double quotes allow a value to contain almost anything. If a value contains no spaces or single or double quotes, it requires no delimiters. - -A more formal [[presentation|Macro Call Syntax]] of this syntax is also available. - -The syntax is actually a shorthand for a <<.wlink MacroCallWidget>> widget. The widget itself offers greater flexibility, including the ability to [[transclude|Transclusion]] parameter values or generate them via additional macros. - -As macros are simply parameterised [[variables|Variables]], a variable's value can be inserted using the same techniques. - -[[Examples|Macro Calls in WikiText (Examples)]] and [[more examples|WikiText parser mode: macro examples]] - -!! Named vs.unnamed parameters - -In the wikitext notation, using named parameters is always the safer choice compared to defining values only. Not naming parameters may have confusing side effects. For example, imagine the first parameter of some macro specifies a [[state tiddler|StateMechanism]] while the second one is intended for a [[template|Transclusion with Templates]] tiddler. Should you accidentally forget to define the first parameter or are confused about the order, the next time your macro is run, which might even be triggered using the preview, your template tiddler may inadvertently be overriden with what was intended to be the state. +See [[Macro Calls]]. \ No newline at end of file diff --git a/editions/tw5.com/tiddlers/wikitext/Macro Calls.tid b/editions/tw5.com/tiddlers/wikitext/Macro Calls.tid new file mode 100644 index 000000000..eddf28200 --- /dev/null +++ b/editions/tw5.com/tiddlers/wikitext/Macro Calls.tid @@ -0,0 +1,58 @@ +caption: Macro Calls +created: 20150220182252000 +modified: 20230419103154328 +tags: WikiText Macros +title: Macro Calls +type: text/vnd.tiddlywiki + +!! Introduction + +This tiddler describes the different ways in which [[macros|Macros]] can be called. + +!! Macro Call Transclusion Shortcut + +To call a [[macro|Macros]], place `<<`double angle brackets`>>` around the name and any parameter values. + +``` +<> +``` + +By default, parameters are listed in the same order as in the macro's definition. A parameter can be labelled with its name and a colon to allow them to be listed in a different order. + +If no value is specified for a parameter, the default value given for that parameter in the [[macro definition|Macro Definitions]] is used instead. (If no default value was defined, the parameter is blank). + +Each parameter value can be enclosed in `'`single quotes`'`, `"`double quotes`"`, `"""`triple double quotes`"""` or `[[`double square brackets`]]`. Triple double quotes allow a value to contain almost anything. If a value contains no spaces or single or double quotes, it requires no delimiters. + +A more formal [[presentation|Macro Call Syntax]] of this syntax is also available. + +See some [[examples|Macro Calls in WikiText (Examples)]] and discussion about [[parser modes|WikiText parser mode: macro examples]]. + +!! Macro Calls with <<.wlink TranscludeWidget>> Widget + +The shortcut syntax expands to the <<.wlink TranscludeWidget>> widget with the `$variable` attribute specifying the name of the macro to transclude. + +``` +<$transclude $variable="mymacro" param="This is the parameter value"/> +``` + +The widget itself offers greater flexibility than the shortcut syntax, including the ability to specify parameter values. + +!! Assigning Macro Calls to Attribute Values + +The result of a macro can be directly assigned to an attribute of a widget or HTML element. The result of the macro is not wikified, but the [[parameter substitution|Macro Parameter Handling]] is performed. + +``` +
>> +... +
+``` + +!! Using Macro Calls in Filters + +Macro calls can be used in filters: + +``` +<$list filter="[]"> +... + +``` \ No newline at end of file diff --git a/editions/tw5.com/tiddlers/wikitext/Macro Definitions in WikiText.tid b/editions/tw5.com/tiddlers/wikitext/Macro Definitions in WikiText.tid index eb74ead1a..9e3d9d1fe 100644 --- a/editions/tw5.com/tiddlers/wikitext/Macro Definitions in WikiText.tid +++ b/editions/tw5.com/tiddlers/wikitext/Macro Definitions in WikiText.tid @@ -1,114 +1,7 @@ -caption: Macro Definitions created: 20150220181617000 -modified: 20221207094236472 -tags: WikiText +modified: 20180820165115455 +tags: title: Macro Definitions in WikiText type: text/vnd.tiddlywiki -A [[macro|Macros]] is defined using a `\define` [[pragma|Pragma]]. Like any pragma, this can only appear at the start of a tiddler. - -The first line of the definition specifies the macro name and any parameters. Each parameter has a name and, optionally, a default value that is used if no value is supplied on a particular call to the macro. - -The lines that follow contain the text of the macro text (i.e. the snippet represented by the macro name), until `\end` appears on a line by itself: - -<$codeblock code={{$:/editions/tw5.com/macro-examples/say-hi}}/> - -Alternatively, the entire definition can be presented on a single line without an `\end` marker: - -``` -\define sayhi(name:"Bugs Bunny") Hi, I'm $name$. -``` - -!! Accessing variables and parameters - -Inside the macro there are several methods for accessing variables defined outside of the macro or parameters from the macro parameter list. - -|syntax|description|h -|`$...$`|Text substitution of a parameter defined in the macro parameters list | -|`<<__...__>>`|Parameter-as-variable access to a parameter defined in the macro parameters list | -|`$(...)$`|Text substitution of a variable defined outside of the macro | -|`<<...>>`|Access to a variable (or other macro) defined outside of the macro | -
- -!!! Placeholders `$(...)$` - -The macro can contain placeholders for parameters. These consist of a parameter name between dollar signs, like `$this$`. - -The macro can also contain placeholders for [[variables|Variables]]. These consist of a variable name (or macro name) between dollar signs and round brackets, like `$(this)$`. - -The actual value of the parameter or variable is substituted for the placeholder whenever the macro is called: - -<$importvariables filter="$:/editions/tw5.com/macro-examples/say-hi-using-variables"> -<$codeblock code={{$:/editions/tw5.com/macro-examples/say-hi-using-variables}}/> -<$macrocall $name=".example" n="1" -eg="""<$set name="address" value="Rabbit Hole Hill"> -<> -"""/> - - -!!! Parameters as Variables `<<__...__>>` - -Parameters in a wikitext macro can be accessed as variables by using the syntax `<<__...__>>`, i.e the parameter name surrounded by double underscores. For example, the example above could also be expressed as: - -``` -\define sayhi(name:"Bugs Bunny") Hi, I'm <$text text=<<__name__>>/>. -``` - -Accessing parameters as variables only works in macros that are wikified and not, for example, when a macro is used as an attribute value. The advantage of the technique is that it avoids the parameter value being substituted into the macro as a literal string, which in turn can help avoid issues with parameters that contain quotes. - -For example, consider this macro. It invokes another macro using the single parameter as an argument for it: - -``` -\define film-quote(line) <$macrocall $name="anothermacro" actor="Bugs Bunny" line="""$line$"""/> -``` - -The code above will fail if the macro is invoked with the argument containing triple double quotes (for example `<>`). Using parameter variables offers a workaround: - -``` -\define film-quote(line) <$macrocall $name="anothermacro" actor="Bugs Bunny" line=<<__line__>>/> -``` - -!! Scope - -Macros are available to the tiddler that defines them, plus any tiddlers that it transcludes. - -To make a macro available to all tiddlers, define it in a tiddler that has the tag <<.tag $:/tags/Macro>>. - -It is also possible to write a macro as a [[JavaScript module|https://tiddlywiki.com/dev/index.html#JavaScript%20Macros]]. ~JavaScript macros are available to all tiddlers, and offer the maximum flexibility. - -A tiddler can manually import macro definitions from a [[selection|Title Selection]] of other tiddlers by using the <<.wlink ImportVariablesWidget>> widget. - -!! Nested Macro Definitions - -Macro definitions can be nested to any number of required levels by specifying the name of the macro in the `\end` marker. Nested macro definitions must appear at the start of the definition that contains them. For example: - -< -\end actions -<$button actions=<>> -$caption$ - -\end special-button - -<> -""">> - -Note that the textual substitution of macro parameters that occurs when the outer macro is rendered will apply to the nested definitions as well. That generally means that textual substitution of macro parameters should not be used within nested macros. - -Parameters of nested macros can also be accessed via the `<<__variablename__>>` syntax. As ordinary variables, these parameters are available within nested child macros (and grandchildren etc). - -For the one-liner macro definition, the `\end` remains unnecessary for the inner macro. For example - -< -<$button actions=<>> -$caption$ - -\end special-button - -<> -""">> - -A more formal [[presentation|Macro Definition Syntax]] of this syntax is also available. - +See [[Macro Definitions]]. diff --git a/editions/tw5.com/tiddlers/wikitext/Macro Definitions.tid b/editions/tw5.com/tiddlers/wikitext/Macro Definitions.tid new file mode 100644 index 000000000..a7d297f93 --- /dev/null +++ b/editions/tw5.com/tiddlers/wikitext/Macro Definitions.tid @@ -0,0 +1,67 @@ +created: 20150220181617000 +modified: 20230419103154328 +tags: WikiText Macros +title: Macro Definitions +type: text/vnd.tiddlywiki + +!! Introduction + +This tiddler describes the different ways in which [[macros|Macros]] can be defined. + +!! Macro Definition Pragma + +Macros are created using the [[Pragma: \define]] at the start of a tiddler. The definitions are available in the rest of the tiddler that defines them, plus any tiddlers that it transcludes. + +``` +\define mymacro(param) +This is the macro text (param=$param$) +\end +``` + +!! Nested Macro Definitions + +Macro definitions can be nested to any number of required levels by specifying the name of the macro in the `\end` marker. Nested macro definitions must appear at the start of the definition that contains them. For example: + +< +\end actions +<$button actions=<>> +$caption$ + +\end special-button + +<> +""">> + +Note that the textual substitution of macro parameters that occurs when the outer macro is rendered will apply to the nested definitions as well. That generally means that textual substitution of macro parameters should not be used within nested macros. + +Parameters of nested macros can also be accessed via the `<<__variablename__>>` syntax. As ordinary variables, these parameters are available within nested child macros (and grandchildren etc). + +!! Macro Definition with Set Widget + +Macros are implemented as a special type of [[variable|Variables]] and so internally are actually defined with a <<.wlink SetWidget>> widget. + +``` +<$set name="mymacro" value="This is the macro text"> +... + +``` + +<<.note """that it is not currently possible to specify parameters when defining a macro with the <<.wlink SetWidget>> widget.""">> + +!! Importing Macro Definitions + +The [[Pragma: \import]] or <<.wlink ImportVariablesWidget>> widget can be used to copy macro definitions from another tiddler. + +!! `$:/tags/Macro` Tag + +Global macros can be defined using the [[SystemTag: $:/tags/Macro]]. + +The tag [[SystemTag: $:/tags/Macro/View]] is used to define macros that should only be available within the main view template and the preview panel. + +The tag [[SystemTag: $:/tags/Macro/View/Body]] is used to define macros that should only be available within the main view template body and the preview panel. + +!! JavaScript Macros + +Macros can also be <<.js-macro-link "written as JavaScript modules">>. diff --git a/editions/tw5.com/tiddlers/wikitext/Macro Parameter Handling.tid b/editions/tw5.com/tiddlers/wikitext/Macro Parameter Handling.tid new file mode 100644 index 000000000..35655334c --- /dev/null +++ b/editions/tw5.com/tiddlers/wikitext/Macro Parameter Handling.tid @@ -0,0 +1,78 @@ +created: 20220917154902906 +modified: 20230419103154328 +tags: WikiText Macros +title: Macro Parameter Handling +type: text/vnd.tiddlywiki + +!! Introduction + +[[Macros]] parameters are handled in two different ways: + +# Textual substitution is always performed for each parameter before the macro contents is used +# When the macro contents are wikified the parameters are made available as variables. The variable names are formed by wrapping the parameter name with double underscores + +Somewhat confusingly, in some situations both of these mechanisms will occur; this is related to the [[pitfalls of using macros|Macro Pitfalls]]. + +!! Textual Substitution of Parameters and variables + +The following substitutions take place before the text of a macro is used: + +* The pattern `$param$` is replaced with the value of the named parameter +* The pattern `$(variable)$` is replaced with the value of the named variable + +The actual value of the parameter or variable is substituted for the placeholder whenever the macro is called: + +<$macrocall $name="wikitext-example-without-html" src="""\define say-hi-using-parameters(name,address) +Hi, I'm $name$ and I live in $address$. +\end + +<> +"""/> + +Here's an example using variable substitution: + +<$macrocall $name="wikitext-example-without-html" src="""\define say-hi-using-variables() +Hi, I'm $(name)$ and I live in $(address)$. +\end + +\define name() Bugs + +<$let address="Rabbit Hole Hill"> +<> + +"""/> + +<<.warning """It is important to note that if the text being inserted contains any substitution tokens then they will in turn be processed. This can lead to unexpected results.""">> + +!! Accessing Parameters as Variables + +When macros are wikified, the parameters can be accessed as variables with the name of the parameter wrapped with double underscores. For example, the parameter `address` would be accessed as the variable `__address__`. + +Thus, the example above could also be expressed as: + +<$macrocall $name="wikitext-example-without-html" src="""\define say-hi-using-parameters(name,address) +Hi, I'm <<__name__>> and I live in <<__address__>>. +\end + +<> +"""/> + +Accessing parameters as variables only works in macros that are wikified and not, for example, when a macro is used as an attribute value. + +!!! Advantages of Accessing Parameters as Variables + +The primary advantage of the technique is that it avoids the parameter value being substituted into the macro as a literal string, which in turn can help avoid issues with parameters that contain quotes. + +For example, consider this macro. It invokes another macro using the single parameter as an argument for it: + +``` +\define film-quote(line) <$macrocall $name="anothermacro" actor="Bugs Bunny" line="""$line$"""/> +``` + +The code above will fail if the macro is invoked with the argument containing triple double quotes (for example `<>`). Using parameter variables offers a workaround: + +``` +\define film-quote(line) <$macrocall $name="anothermacro" actor="Bugs Bunny" line=<<__line__>>/> +``` + +See [[Macro Pitfalls]] for more discussion. diff --git a/editions/tw5.com/tiddlers/wikitext/Macro Pitfalls.tid b/editions/tw5.com/tiddlers/wikitext/Macro Pitfalls.tid new file mode 100644 index 000000000..cd0ed4061 --- /dev/null +++ b/editions/tw5.com/tiddlers/wikitext/Macro Pitfalls.tid @@ -0,0 +1,39 @@ +created: 20220917091428117 +modified: 20230419103154328 +title: Macro Pitfalls +type: text/vnd.tiddlywiki + +! Introduction + +In the early days of TiddlyWiki, [[macros|Macros]] were the best way of encapsulating snippets for reuse, and so they were used extensively. However, they have always suffered from some significant disadvantages that can give rise to errors and poor performance. + +<<.from-version "5.3.0">> Macros have been joined by [[Procedures]], [[Custom Widgets]] and [[Functions]] which together provide more robust and flexible ways to encapsulate and re-use code. It is now recommended to only use macros when textual substitution is specifically required. + +! Shortcomings of Textual Substitution + +TiddlyWiki's handling of [[macro|Macros]] parameters is based on "textual substitution" which means that the string values of the parameters provided when calling a macro are plugged into the macro definition before it is wikified. + +Here's a typical example of the approach in early versions of TiddlyWiki 5. The intention is to provide a macro that takes a single parameter of the title of the tiddler to view: + +``` +\define mymacro(title) +<$codeblock code={{$title$}}/> +\end +``` + +That works for simple cases like `<>` but is subtly brittle. For example, the macro above would fail with tiddler titles containing double closing curly braces. Trying to use it with the title `foo}}bar` would lead to the macro being expanded to the following invalid syntax: + +``` +<$codeblock code={{foo}}bar}}/> +``` + +As a result of this issue, for many years the TiddlyWiki 5 user interface failed if a variety of combinations of special characters were encountered in tiddler titles. + +This issue has been mitigated over the years, particularly by providing access to the macro parameters as variables. However, for backwards compatibility, this was done without affecting the existing syntax, which required us to adopt the clumsy protocol of wrapping the parameter name in double underscores to get the name of the corresponding variable. + +! Performance of Global Macros + +Global [[Macro Definitions]] defined with the [[SystemTag: $:/tags/Macro]] suffer from poor performance because every macro has to be parsed regardless of whether it is actually used. + +Furthermore, the way that definitions are imported means that updating a tiddler tagged [[SystemTag: $:/tags/Macro]] will cause the entire page to be refreshed. + diff --git a/editions/tw5.com/tiddlers/wikitext/Macros in WikiText.tid b/editions/tw5.com/tiddlers/wikitext/Macros in WikiText.tid index a738d5389..16f05a22a 100644 --- a/editions/tw5.com/tiddlers/wikitext/Macros in WikiText.tid +++ b/editions/tw5.com/tiddlers/wikitext/Macros in WikiText.tid @@ -1,11 +1,7 @@ created: 20131205160746466 modified: 20150221094003000 -tags: WikiText +tags: title: Macros in WikiText type: text/vnd.tiddlywiki -caption: Macros -The use of [[macros|Macros]] in WikiText has two distinct aspects: - -* [[Defining macros|Macro Definitions in WikiText]] -* [[Calling macros|Macro Calls in WikiText]] +See [[Macros]]. \ No newline at end of file diff --git a/editions/tw5.com/tiddlers/wikitext/Transclusion and Substitution.tid b/editions/tw5.com/tiddlers/wikitext/Transclusion and Substitution.tid index c74c68855..8d0a52cdc 100644 --- a/editions/tw5.com/tiddlers/wikitext/Transclusion and Substitution.tid +++ b/editions/tw5.com/tiddlers/wikitext/Transclusion and Substitution.tid @@ -1,5 +1,5 @@ created: 20141018090608643 -modified: 20211117212543789 +modified: 20230419103154329 tags: WikiText title: Transclusion and Substitution type: text/vnd.tiddlywiki @@ -55,6 +55,6 @@ As described in [[Introduction to filter notation]], you can also transclude a v ! Textual Substitution -Textual substitution occurs when the value of a macro/variable is used. It is described in [[Macros in WikiText]]. +Textual substitution occurs when the value of a macro/variable is used. It is described in [[Macros]]. The key difference between substitution and transclusion is that substitution occurs before WikiText parsing. This means that you can use substitution to build WikiText constructions. Transclusions are processed independently, and cannot be combined with adjacent text to define WikiText constructions. diff --git a/editions/tw5.com/tiddlers/wikitext/Transclusion in WikiText.tid b/editions/tw5.com/tiddlers/wikitext/Transclusion in WikiText.tid index f7de5d83d..838cd0ade 100644 --- a/editions/tw5.com/tiddlers/wikitext/Transclusion in WikiText.tid +++ b/editions/tw5.com/tiddlers/wikitext/Transclusion in WikiText.tid @@ -12,6 +12,8 @@ You can incorporate the content of one tiddler within another using the [[Transc * `{{MyTiddler}}` transcludes a single tiddler * `{{MyTiddler||TemplateTitle}}` displays the tiddler through a specified [[TemplateTiddler|TemplateTiddlers]] * `{{||TemplateTitle}}` displays the specified template tiddler without altering the [[current tiddler|Current Tiddler]] +* `{{MyTiddler|Parameter}}` transcludes a single tiddler with a single parameter +* `{{MyTiddler||TemplateTitle|Parameter|SecondParameter}}` transcludes a single tiddler through a specified [[TemplateTiddler|TemplateTiddlers]] with two parameters !! Transcluding Text References @@ -37,7 +39,7 @@ The WikiText transclusion syntax generates a TiddlerWidget wrapped around a Tran ``` <$tiddler tiddler="MyTiddler"> -<$transclude tiddler="MyTemplate" field="myField"/> +<$transclude $tiddler="MyTemplate" $field="myField"/> ``` diff --git a/editions/tw5.com/tiddlers/wikitext/Variables in WikiText.tid b/editions/tw5.com/tiddlers/wikitext/Variables in WikiText.tid index b2c103507..a412031c3 100644 --- a/editions/tw5.com/tiddlers/wikitext/Variables in WikiText.tid +++ b/editions/tw5.com/tiddlers/wikitext/Variables in WikiText.tid @@ -1,36 +1,7 @@ -caption: Variables created: 20141002141231992 modified: 20150221221850000 -tags: WikiText +tags: title: Variables in WikiText type: text/vnd.tiddlywiki -See also the [[introduction to the concept of variables|Variables]]. - -To transclude the value of a variable, use the [[macro call syntax|Macro Calls in WikiText]] with no parameters. You can also use a <<.wlink MacroCallWidget>> widget. - -A [[macro|Macros]] snippet can contain `$(name)$` as a [[placeholder|Macro Definitions in WikiText]] for which the value of the variable of that name will be substituted. - -A variable's value can be used as a [[filter parameter|Filter Parameter]], or as a [[widget attribute|Widgets in WikiText]]. The latter supports macro parameters. - -!! Example: defining a variable - -<$macrocall $name=".example" n="1" -eg="""<$set name=animal value=zebra> -<> -"""/> - -!! Example: defining a macro - -The `\define` pragma below [[defines a macro|Macros in WikiText]] called <<.var tags-of-current-tiddler>>. The macro returns the value of the tiddler's <<.field tags>> field, and can be accessed from anywhere else in the same tiddler (or in any tiddler that [[imports|ImportVariablesWidget]] it). - -<$importvariables filter="$:/editions/tw5.com/macro-examples/tags-of-current-tiddler"> -<$codeblock code={{$:/editions/tw5.com/macro-examples/tags-of-current-tiddler}}/> -<$macrocall $name=".example" n="2" eg="""The tags are: <>"""/> - - -!! Example: using a variable as a filter parameter - -This example uses the <<.olink backlinks>> [[operator|Filter Operators]] to list all tiddlers that link to this one. - -<$macrocall $name=".example" n="3" eg="""<backlinks[]]">>"""/> +See [[Variables]]. \ No newline at end of file diff --git a/editions/tw5.com/tiddlers/wikitext/parser/Inline Mode WikiText.tid b/editions/tw5.com/tiddlers/wikitext/parser/Inline Mode WikiText.tid index 88afd8372..3e04a01ac 100644 --- a/editions/tw5.com/tiddlers/wikitext/parser/Inline Mode WikiText.tid +++ b/editions/tw5.com/tiddlers/wikitext/parser/Inline Mode WikiText.tid @@ -1,6 +1,6 @@ caption: inline parser mode created: 20220111000108618 -modified: 20220122182842036 +modified: 20220917074925230 tags: [[WikiText Parser Modes]] title: Inline Mode WikiText type: text/vnd.tiddlywiki @@ -14,13 +14,13 @@ These WikiText types can be expressed without an entire line of text. They aren' * [[HTML in WikiText]] * [[Images in WikiText]] * [[Linking in WikiText]] -* [[Macro Calls in WikiText]] +* [[Macro Calls]] * [[Styles and Classes in WikiText]] (single line version only) * [[Transclusion in WikiText]] * [[Variables in WikiText]] * [[Widgets in WikiText]] -<<.tip """[[Macro Calls in WikiText]] and [[Transclusion in WikiText]] will be recognised in block mode if the macro call or transclusion spans an entire line.""">> +<<.tip """[[Macro Calls]] and [[Transclusion in WikiText]] will be recognised in block mode if the macro call or transclusion spans an entire line.""">> <<.tip """The other ''inline mode'' WikiText types are technically <<.em only>> detected while the parser is in ''inline mode''. However, the opening punctuation will also trigger the start of [[Paragraphs in WikiText]] which will automatically cause the parser to go into ''inline mode''. Therefore, practically speaking, it is just as useful to consider these WikiText types as recognised while the parser is in either ''inline mode'' or ''block mode''""">> While processing the //enclosed// text of some of these WikiText types, the parser [[will not look for new WikiText|Places where the parser ignores WikiText]]. But for rest of these WikiText types, the parser will continue in ''inline mode'' for the //enclosed// text. While parsing that text, it might encounter something which [[moves it to block mode|WikiText parser mode transitions]]. \ No newline at end of file diff --git a/editions/tw5.com/tiddlers/wikitext/parser/Places where the parser ignores WikiText.tid b/editions/tw5.com/tiddlers/wikitext/parser/Places where the parser ignores WikiText.tid index afb9db192..d52193148 100644 --- a/editions/tw5.com/tiddlers/wikitext/parser/Places where the parser ignores WikiText.tid +++ b/editions/tw5.com/tiddlers/wikitext/parser/Places where the parser ignores WikiText.tid @@ -8,7 +8,7 @@ type: text/vnd.tiddlywiki Text enclosed by these constructs is skipped by the parser and WikiText punctuation will be ignored: |[[Code Blocks in WikiText]]|One of the main purposes of code blocks is to suppress wikitext expansion. Once the code block starts, the parser will ignore all WikiText punctuation until the code block ends.| -|[[Images in WikiText]]|`[[img|literal image link text]]` - the text enclosed by square braces will be ignored. This means, for example, [[transclusions|Transclusion in WikiText]] and [[macro calls|Macro Calls in WikiText]] cannot be used to dynamically construct the link text| -|[[Linking in WikiText]]|`[[literal link target|literal link text]]` - the text enclosed by square braces will be ignored. This means, for example, [[transclusions|Transclusion in WikiText]] and [[macro calls|Macro Calls in WikiText]] cannot be used to dynamically construct the link target or the link text| -|[[Macro Calls in WikiText]]|`<>" {{transclusion_ignored}}>>` - while processing the text enclosed by a macro call, the parser will follow special rules for detecting macro parameters. These rules do not include detection of WikiText. However, after the parameters are substituted into the macro definition, the result will be parsed using [[normal rules|Wiki Text Parser Modes]]. This will likely result in the detection of any WikiText.| +|[[Images in WikiText]]|`[[img|literal image link text]]` - the text enclosed by square braces will be ignored. This means, for example, [[transclusions|Transclusion in WikiText]] and [[macro calls|Macro Calls]] cannot be used to dynamically construct the link text| +|[[Linking in WikiText]]|`[[literal link target|literal link text]]` - the text enclosed by square braces will be ignored. This means, for example, [[transclusions|Transclusion in WikiText]] and [[macro calls|Macro Calls]] cannot be used to dynamically construct the link target or the link text| +|[[Macro Calls]]|`<>" {{transclusion_ignored}}>>` - while processing the text enclosed by a macro call, the parser will follow special rules for detecting macro parameters. These rules do not include detection of WikiText. However, after the parameters are substituted into the macro definition, the result will be parsed using [[normal rules|Wiki Text Parser Modes]]. This will likely result in the detection of any WikiText.| diff --git a/editions/tw5.com/tiddlers/wikitext/parser/WikiText Parser Modes.tid b/editions/tw5.com/tiddlers/wikitext/parser/WikiText Parser Modes.tid index 8056b9493..bd408b977 100644 --- a/editions/tw5.com/tiddlers/wikitext/parser/WikiText Parser Modes.tid +++ b/editions/tw5.com/tiddlers/wikitext/parser/WikiText Parser Modes.tid @@ -6,7 +6,7 @@ type: text/vnd.tiddlywiki In order to display Tiddlers (usually the text field), the WikiText parser reads and interprets the content and applies WikiText rules. The parser has three modes: -* ''pragma mode'' - the parser will recognise only [[pragma mode WikiText|Pragma]] punctuation +* ''pragma mode'' - the parser will recognise only [[pragma mode WikiText|Pragmas]] punctuation * ''block mode'' - the parser will recognise only [[block mode WikiText|Block Mode WikiText]] punctuation * ''inline mode'' - the parser will recognise only [[inline mode WikiText|Inline Mode WikiText]] diff --git a/editions/tw5.com/tiddlers/wikitext/parser/WikiText parser mode transitions.tid b/editions/tw5.com/tiddlers/wikitext/parser/WikiText parser mode transitions.tid index 009c3d3f3..6150fbf63 100644 --- a/editions/tw5.com/tiddlers/wikitext/parser/WikiText parser mode transitions.tid +++ b/editions/tw5.com/tiddlers/wikitext/parser/WikiText parser mode transitions.tid @@ -27,11 +27,11 @@ This is a <<.em rough>> diagram whose lines mostly correspond to the parser mode By default the parser starts in [[block mode|Block Mode WikiText]]. However, a tiddler can instead be transcluded with [[inline mode|Inline Mode WikiText]] in which case [[block mode WikiText|Block Mode WikiText]] will not be recognised. -At the start of text only, the parser will also recognise any [[pragma mode WikiText|Pragma]]. +At the start of text only, the parser will also recognise any [[pragma mode WikiText|Pragmas]]. !! Transitions from pragma mode -At the start of text, the parser will recognise any [[pragma|Pragma]]. If none are found then it will move to [[inline|Inline Mode WikiText]] or [[block|Block Mode WikiText]] mode depending on the transclusion mode. If any [[pragma|Pragma]] are found then it will continue looking for [[pragma|Pragma]] until it finds one or more blank lines not followed by the start of a new pragma. +At the start of text, the parser will recognise any [[pragma|Pragmas]]. If none are found then it will move to [[inline|Inline Mode WikiText]] or [[block|Block Mode WikiText]] mode depending on the transclusion mode. If any [[pragma|Pragmas]] are found then it will continue looking for [[pragma|Pragmas]] until it finds one or more blank lines not followed by the start of a new pragma. !! Transitions from block mode diff --git a/editions/tw5.com/tiddlers/wikitext/parser/WikiText parser mode_ macro examples.tid b/editions/tw5.com/tiddlers/wikitext/parser/WikiText parser mode_ macro examples.tid index 07a08db46..7224ddb81 100644 --- a/editions/tw5.com/tiddlers/wikitext/parser/WikiText parser mode_ macro examples.tid +++ b/editions/tw5.com/tiddlers/wikitext/parser/WikiText parser mode_ macro examples.tid @@ -25,7 +25,7 @@ then """>> -The list syntax is recognised in [[block mode|Block Mode WikiText]] and the enclosed contents are parsed using [[inline mode|Inline Mode WikiText]]. When the parser encounters a [[wikitext macro call|Macro Calls in WikiText]] it will use the current parse mode to parse the contents of the macro. The contents of the macro contains table syntax which is only recognised in [[block mode|Block Mode WikiText]]. +The list syntax is recognised in [[block mode|Block Mode WikiText]] and the enclosed contents are parsed using [[inline mode|Inline Mode WikiText]]. When the parser encounters a [[wikitext macro call|Macro Calls]] it will use the current parse mode to parse the contents of the macro. The contents of the macro contains table syntax which is only recognised in [[block mode|Block Mode WikiText]]. Therefore, in #1 above the table syntax is not recognised. In #2 above, the blank line after the open `div` tag moves the parser back into [[block mode|Block Mode WikiText]], the macro call inherits it and the table is recognised. diff --git a/package.json b/package.json index f65fda395..3d9444256 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "tiddlywiki", "preferGlobal": "true", - "version": "5.2.8-prerelease", + "version": "5.3.0-prerelease", "author": "Jeremy Ruston ", "description": "a non-linear personal web notebook", "contributors": [ diff --git a/themes/tiddlywiki/vanilla/base.tid b/themes/tiddlywiki/vanilla/base.tid index 98097296a..f63384ee9 100644 --- a/themes/tiddlywiki/vanilla/base.tid +++ b/themes/tiddlywiki/vanilla/base.tid @@ -3118,6 +3118,36 @@ select { background: <>; } +/* +** Classes for displaying globals +*/ + +.tc-global-tiddler-body { + padding: 0.25em; + border: 1px solid <>; + background-color: <>; + border-radius: 3px; +} + +.tc-global-tiddler-body-heading { + margin: 0 0 0.25em 0; + font-weight: normal; +} + +.tc-global-tiddler-body-type { + margin: 0 0 0.25em 0; + border-bottom: 1px solid <>; +} + +.tc-global-tiddler-body-details { + background-color: <>; +} + +.tc-global-tiddler-body pre { + margin: 0; + border: 1px solid <>; +} + /* ** Utility classes for SVG icons */