1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-23 10:07:19 +00:00

Added support for parameterised transclusions

Still no protection against infinite transclusion loops
This commit is contained in:
Jeremy Ruston 2011-12-09 10:17:41 +00:00
parent a5a0567fe9
commit ad5356f2f3
7 changed files with 19 additions and 16 deletions

View File

@ -7,6 +7,7 @@ Wiki text macro implementation
"use strict";
var ArgParser = require("./ArgParser.js").ArgParser,
WikiTextParserModule = require("./WikiTextParser.js"),
utils = require("./Utils.js"),
util = require("util");
@ -69,17 +70,19 @@ wikiTextMacros.macros = {
tiddler: {
handler: function(macroNode,store,tiddler) {
var args = new ArgParser(macroNode.params,{defaultName:"name"}),
title = args.getValueByName("name",null),
withTokens = args.getValuesByName("with",[]);
if(withTokens.length > 0) {
} else {
// There are no substitution tokens, so just copy the parse tree of the tiddler
var copy = utils.deepCopy(store.getTiddler(title).getParseTree().tree);
for(var t=0; t<copy.length; t++) {
macroNode.output.push(copy[t]);
}
targetTitle = args.getValueByName("name",null),
withTokens = args.getValuesByName("with",[]),
text = store.getTiddlerText(targetTitle,"");
for(t=0; t<withTokens.length; t++) {
var placeholderRegExp = new RegExp("\\$"+(t+1),"mg");
text = text.replace(placeholderRegExp,withTokens[t]);
}
var parseTree = new WikiTextParserModule.WikiTextParser(text);
for(var t=0; t<parseTree.tree.length; t++) {
macroNode.output.push(parseTree.tree[t]);
}
// Execute any macros in the copy
wikiTextMacros.executeMacros(macroNode.output,store,tiddler);
}
},
timeline: {

View File

@ -1 +1 @@
An image <img src="Something.jpg" /> and a couple of &#xc7; &#199; &quot;HTML Entity&quot;
An image <img src="Something.jpg" /> and a $1 couple of &#xc7; &#199; &quot;HTML Entity&quot; and macro 0.0.0

View File

@ -1,3 +1,3 @@
title: Fourth Tiddler
An image [img[Something.jpg]] and a couple of &#xc7; &#199; &quot;HTML Entity&quot;
An image [img[Something.jpg]] and a $1 couple of &#xc7; &#199; &quot;HTML Entity&quot; and macro <<version>>

View File

@ -1 +1 @@
An image and a couple of Ç Ç "HTML Entity"
An image and a $1 couple of Ç Ç "HTML Entity" and macro 0.0.0

View File

@ -1 +1 @@
An explicit link <a href="Fourth Tiddler">Fourth Tiddler</a> and <a href="Fourth Tiddler">a pretty link</a> and a transclusion An image <img src="Something.jpg" /> and a couple of &#xc7; &#199; &quot;HTML Entity&quot;
An explicit link <a href="Fourth Tiddler">Fourth Tiddler</a> and <a href="Fourth Tiddler">a pretty link</a> and a transclusion An image <img src="Something.jpg" /> and a Stringy couple of &#xc7; &#199; &quot;HTML Entity&quot; and macro 0.0.0

View File

@ -1,3 +1,3 @@
title: ThirdTiddler
An explicit link [[Fourth Tiddler]] and [[a pretty link|Fourth Tiddler]] and a transclusion <<tiddler [[Fourth Tiddler]]>>
An explicit link [[Fourth Tiddler]] and [[a pretty link|Fourth Tiddler]] and a transclusion <<tiddler [[Fourth Tiddler]] with:Stringy>>

View File

@ -1 +1 @@
An explicit link Fourth Tiddler and a pretty link and a transclusion An image and a couple of Ç Ç "HTML Entity"
An explicit link Fourth Tiddler and a pretty link and a transclusion An image and a Stringy couple of Ç Ç "HTML Entity" and macro 0.0.0