diff --git a/core/modules/parsers/wikiparser/rules/transcludeblock.js b/core/modules/parsers/wikiparser/rules/transcludeblock.js index f80af83b4..21c211a5a 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: "ubertransclude", attributes: {}, isBlock: true }; + $tw.utils.each(params,function(paramValue,index) { + var name = "" + index; + transcludeNode.attributes["" + index] = { + name: name, + type: "string", + value: paramValue + } + }); // Prepare the tiddler widget var tr, targetTitle, targetField, targetIndex, tiddlerNode; if(textRef) { diff --git a/core/modules/parsers/wikiparser/rules/transcludeinline.js b/core/modules/parsers/wikiparser/rules/transcludeinline.js index 5b28ff794..0b9d771ad 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: "ubertransclude", attributes: {} }; + $tw.utils.each(params,function(paramValue,index) { + var name = "" + index; + transcludeNode.attributes["" + index] = { + name: name, + type: "string", + value: paramValue + } + }); // Prepare the tiddler widget var tr, targetTitle, targetField, targetIndex, tiddlerNode; if(textRef) { diff --git a/editions/test/tiddlers/tests/data/ubertransclusion/Parameterised-Positional-Shortcut.tid b/editions/test/tiddlers/tests/data/ubertransclusion/Parameterised-Positional-Shortcut.tid new file mode 100644 index 000000000..43c498bbd --- /dev/null +++ b/editions/test/tiddlers/tests/data/ubertransclusion/Parameterised-Positional-Shortcut.tid @@ -0,0 +1,29 @@ +title: Ubertransclude/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'> +(<$ubertransclude 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