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:
parent
a5a0567fe9
commit
ad5356f2f3
@ -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: {
|
||||
|
@ -1 +1 @@
|
||||
An image <img src="Something.jpg" /> and a couple of Ç Ç "HTML Entity"
|
||||
An image <img src="Something.jpg" /> and a $1 couple of Ç Ç "HTML Entity" and macro 0.0.0
|
@ -1,3 +1,3 @@
|
||||
title: Fourth Tiddler
|
||||
|
||||
An image [img[Something.jpg]] and a couple of Ç Ç "HTML Entity"
|
||||
An image [img[Something.jpg]] and a $1 couple of Ç Ç "HTML Entity" and macro <<version>>
|
@ -1 +1 @@
|
||||
An image and a couple of Ç Ç "HTML Entity"
|
||||
An image and a $1 couple of Ç Ç "HTML Entity" and macro 0.0.0
|
@ -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 Ç Ç "HTML Entity"
|
||||
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 Ç Ç "HTML Entity" and macro 0.0.0
|
@ -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>>
|
@ -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
|
Loading…
Reference in New Issue
Block a user