mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-12-24 00:50:28 +00:00
Added support for the "with" parameter to the tiddler macro
This commit is contained in:
parent
c865fabd3c
commit
5bb2a1e1b7
@ -15,10 +15,23 @@ exports.macro = {
|
||||
cascadeParams: true, // Cascade names of named parameters to following anonymous parameters
|
||||
params: {
|
||||
target: {byName: "default", type: "tiddler", optional: false},
|
||||
"with": {byName: true, type: "text", optional: true}
|
||||
"with": {byName: true, type: "text", optional: true, dependentAll: true}
|
||||
},
|
||||
code: function(type,tiddler,store,params) {
|
||||
return store.renderTiddler(type,params.target);
|
||||
if(params["with"]) {
|
||||
// Parameterised transclusion
|
||||
var targetTiddler = store.getTiddler(params.target),
|
||||
text = targetTiddler.fields.text;
|
||||
var withTokens = [params["with"]];
|
||||
for(var t=0; t<withTokens.length; t++) {
|
||||
var placeholderRegExp = new RegExp("\\$"+(t+1),"mg");
|
||||
text = text.replace(placeholderRegExp,withTokens[t]);
|
||||
}
|
||||
return store.renderText(targetTiddler.fields.type,text,type,tiddler.fields.title);
|
||||
} else {
|
||||
// There's no parameterisation, so we can just render the target tiddler directly
|
||||
return store.renderTiddler(type,params.target,tiddler.fields.title);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user