mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-09-30 07:50:47 +00:00
Add support for shortcut syntax for positional transclusion parameters
This commit is contained in:
parent
89b7a3bd28
commit
5bcf7b9edd
@ -23,7 +23,7 @@ exports.types = {block: true};
|
|||||||
exports.init = function(parser) {
|
exports.init = function(parser) {
|
||||||
this.parser = parser;
|
this.parser = parser;
|
||||||
// Regexp to match
|
// Regexp to match
|
||||||
this.matchRegExp = /\{\{([^\{\}\|]*)(?:\|\|([^\|\{\}]+))?\}\}(?:\r?\n|$)/mg;
|
this.matchRegExp = /\{\{([^\{\}\|]*)(?:\|\|([^\|\{\}]+))?(?:\|([^\{\}]+))?\}\}(?:\r?\n|$)/mg;
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.parse = function() {
|
exports.parse = function() {
|
||||||
@ -31,13 +31,22 @@ exports.parse = function() {
|
|||||||
this.parser.pos = this.matchRegExp.lastIndex;
|
this.parser.pos = this.matchRegExp.lastIndex;
|
||||||
// Get the match details
|
// Get the match details
|
||||||
var template = $tw.utils.trim(this.match[2]),
|
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
|
// Prepare the transclude widget
|
||||||
var transcludeNode = {
|
var transcludeNode = {
|
||||||
type: "ubertransclude",
|
type: "ubertransclude",
|
||||||
attributes: {},
|
attributes: {},
|
||||||
isBlock: true
|
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
|
// Prepare the tiddler widget
|
||||||
var tr, targetTitle, targetField, targetIndex, tiddlerNode;
|
var tr, targetTitle, targetField, targetIndex, tiddlerNode;
|
||||||
if(textRef) {
|
if(textRef) {
|
||||||
|
@ -23,7 +23,7 @@ exports.types = {inline: true};
|
|||||||
exports.init = function(parser) {
|
exports.init = function(parser) {
|
||||||
this.parser = parser;
|
this.parser = parser;
|
||||||
// Regexp to match
|
// Regexp to match
|
||||||
this.matchRegExp = /\{\{([^\{\}\|]*)(?:\|\|([^\|\{\}]+))?\}\}/mg;
|
this.matchRegExp = /\{\{([^\{\}\|]*)(?:\|\|([^\|\{\}]+))?(?:\|([^\{\}]+))?\}\}/mg;
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.parse = function() {
|
exports.parse = function() {
|
||||||
@ -31,12 +31,21 @@ exports.parse = function() {
|
|||||||
this.parser.pos = this.matchRegExp.lastIndex;
|
this.parser.pos = this.matchRegExp.lastIndex;
|
||||||
// Get the match details
|
// Get the match details
|
||||||
var template = $tw.utils.trim(this.match[2]),
|
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
|
// Prepare the transclude widget
|
||||||
var transcludeNode = {
|
var transcludeNode = {
|
||||||
type: "ubertransclude",
|
type: "ubertransclude",
|
||||||
attributes: {}
|
attributes: {}
|
||||||
};
|
};
|
||||||
|
$tw.utils.each(params,function(paramValue,index) {
|
||||||
|
var name = "" + index;
|
||||||
|
transcludeNode.attributes["" + index] = {
|
||||||
|
name: name,
|
||||||
|
type: "string",
|
||||||
|
value: paramValue
|
||||||
|
}
|
||||||
|
});
|
||||||
// Prepare the tiddler widget
|
// Prepare the tiddler widget
|
||||||
var tr, targetTitle, targetField, targetIndex, tiddlerNode;
|
var tr, targetTitle, targetField, targetIndex, tiddlerNode;
|
||||||
if(textRef) {
|
if(textRef) {
|
||||||
|
@ -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=<<zero>>/>}{<$text text=<<one>>/>}{<$text text=<<two>>/>}]</$parameters>
|
||||||
|
_
|
||||||
|
title: TiddlerTwo
|
||||||
|
|
||||||
|
\whitespace trim
|
||||||
|
<$parameters zero='Mouse' one='Horse' two='Owl'>
|
||||||
|
(<$ubertransclude zero=<<zero>> one=<<one>> two=<<two>>/>)
|
||||||
|
</$parameters>
|
||||||
|
_
|
||||||
|
title: ExpectedResult
|
||||||
|
|
||||||
|
<p>[{Jaguar}{Lizard}{Mole}]</p><p>[{Ferret}{Lizard}{Mole}]</p><p>[{Butterfly}{Moth}{Mole}]</p><p>[{Beetle}{Scorpion}{Snake}]</p><p>([{Beetle}{Scorpion}{Snake}])</p>
|
Loading…
Reference in New Issue
Block a user