mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-08-09 07:15:39 +00:00
Added support for transclusion macro
This commit is contained in:
parent
ff73987457
commit
a5a0567fe9
@ -56,10 +56,10 @@ var ArgParser = function(argString,options) {
|
|||||||
this.byPos.push({n:"", v:n});
|
this.byPos.push({n:"", v:n});
|
||||||
} else {
|
} else {
|
||||||
v = parseToken(match,8);
|
v = parseToken(match,8);
|
||||||
if(v === null && options.defaultName) {
|
if(v == null && options.defaultName) {
|
||||||
v = n;
|
v = n;
|
||||||
n = options.defaultName;
|
n = options.defaultName;
|
||||||
} else if(v === null && options.defaultValue) {
|
} else if(v == null && options.defaultValue) {
|
||||||
v = options.defaultValue;
|
v = options.defaultValue;
|
||||||
}
|
}
|
||||||
this.byPos.push({n:n, v:v});
|
this.byPos.push({n:n, v:v});
|
||||||
|
19
js/Utils.js
19
js/Utils.js
@ -9,6 +9,25 @@ This file is a bit of a dumping ground; the expectation is that most of these fu
|
|||||||
|
|
||||||
var utils = exports;
|
var utils = exports;
|
||||||
|
|
||||||
|
|
||||||
|
utils.deepCopy = function(v) {
|
||||||
|
var r,t;
|
||||||
|
if(v instanceof Array) {
|
||||||
|
r = [];
|
||||||
|
for(t=0; t<v.length; t++) {
|
||||||
|
r.push(utils.deepCopy(v[t]));
|
||||||
|
}
|
||||||
|
} else if (v === Object(v)) {
|
||||||
|
r = {};
|
||||||
|
for(t in v) {
|
||||||
|
r[t] = utils.deepCopy(v[t]);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
r = v;
|
||||||
|
}
|
||||||
|
return r;
|
||||||
|
};
|
||||||
|
|
||||||
// Pad a string to a certain length with zeros
|
// Pad a string to a certain length with zeros
|
||||||
utils.zeroPad = function(n,d)
|
utils.zeroPad = function(n,d)
|
||||||
{
|
{
|
||||||
|
@ -12,22 +12,22 @@ var ArgParser = require("./ArgParser.js").ArgParser,
|
|||||||
|
|
||||||
var wikiTextMacros = exports;
|
var wikiTextMacros = exports;
|
||||||
|
|
||||||
wikiTextMacros.executeMacros = function(tree,store) {
|
wikiTextMacros.executeMacros = function(tree,store,tiddler) {
|
||||||
for(var t=0; t<tree.length; t++) {
|
for(var t=0; t<tree.length; t++) {
|
||||||
if(tree[t].type === "macro") {
|
if(tree[t].type === "macro") {
|
||||||
wikiTextMacros.executeMacro(tree[t],store);
|
wikiTextMacros.executeMacro(tree[t],store,tiddler);
|
||||||
}
|
}
|
||||||
if(tree[t].children) {
|
if(tree[t].children) {
|
||||||
wikiTextMacros.executeMacros(tree[t].children,store);
|
wikiTextMacros.executeMacros(tree[t].children,store,tiddler);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
wikiTextMacros.executeMacro = function(macroNode,store) {
|
wikiTextMacros.executeMacro = function(macroNode,store,tiddler) {
|
||||||
var macroInfo = wikiTextMacros.macros[macroNode.name];
|
var macroInfo = wikiTextMacros.macros[macroNode.name];
|
||||||
macroNode.output = [];
|
macroNode.output = [];
|
||||||
if(macroInfo) {
|
if(macroInfo) {
|
||||||
macroInfo.handler(macroNode,store);
|
macroInfo.handler(macroNode,store,tiddler);
|
||||||
} else {
|
} else {
|
||||||
macroNode.output.push({type: "text", value: "Unknown macro " + macroNode.name});
|
macroNode.output.push({type: "text", value: "Unknown macro " + macroNode.name});
|
||||||
}
|
}
|
||||||
@ -35,47 +35,59 @@ wikiTextMacros.executeMacro = function(macroNode,store) {
|
|||||||
|
|
||||||
wikiTextMacros.macros = {
|
wikiTextMacros.macros = {
|
||||||
allTags: {
|
allTags: {
|
||||||
handler: function(macroNode,store) {
|
handler: function(macroNode,store,tiddler) {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
br: {
|
br: {
|
||||||
handler: function(macroNode,store) {
|
handler: function(macroNode,store,tiddler) {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
list: {
|
list: {
|
||||||
handler: function(macroNode,store) {
|
handler: function(macroNode,store,tiddler) {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
slider: {
|
slider: {
|
||||||
handler: function(macroNode,store) {
|
handler: function(macroNode,store,tiddler) {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
tabs: {
|
tabs: {
|
||||||
handler: function(macroNode,store) {
|
handler: function(macroNode,store,tiddler) {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
tag: {
|
tag: {
|
||||||
handler: function(macroNode,store) {
|
handler: function(macroNode,store,tiddler) {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
tagging: {
|
tagging: {
|
||||||
handler: function(macroNode,store) {
|
handler: function(macroNode,store,tiddler) {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
tags: {
|
tags: {
|
||||||
handler: function(macroNode,store) {
|
handler: function(macroNode,store,tiddler) {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
tiddler: {
|
tiddler: {
|
||||||
handler: function(macroNode,store) {
|
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]);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
timeline: {
|
timeline: {
|
||||||
handler: function(macroNode,store) {
|
handler: function(macroNode,store,tiddler) {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
today: {
|
today: {
|
||||||
handler: function(macroNode,store) {
|
handler: function(macroNode,store,tiddler) {
|
||||||
var now = new Date(),
|
var now = new Date(),
|
||||||
args = new ArgParser(macroNode.params,{noNames:true}),
|
args = new ArgParser(macroNode.params,{noNames:true}),
|
||||||
value = args.byPos[0] ? utils.formatDateString(now,args.byPos[0].v) : now.toLocaleString();
|
value = args.byPos[0] ? utils.formatDateString(now,args.byPos[0].v) : now.toLocaleString();
|
||||||
@ -83,13 +95,12 @@ wikiTextMacros.macros = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
version: {
|
version: {
|
||||||
handler: function(macroNode,store) {
|
handler: function(macroNode,store,tiddler) {
|
||||||
macroNode.output.push({type: "text", value: "0.0.0"});
|
macroNode.output.push({type: "text", value: "0.0.0"});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
view: {
|
view: {
|
||||||
handler: function(macroNode,store) {
|
handler: function(macroNode,store,tiddler) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -101,7 +101,7 @@ WikiTextParser.prototype.renderAsHtml = function(store,title) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
wikiTextMacros.executeMacros(this.tree,this.store);
|
wikiTextMacros.executeMacros(this.tree,store);
|
||||||
renderSubTree(this.tree);
|
renderSubTree(this.tree);
|
||||||
return output.join("");
|
return output.join("");
|
||||||
};
|
};
|
||||||
@ -131,6 +131,7 @@ WikiTextParser.prototype.renderAsText = function(store,title) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
wikiTextMacros.executeMacros(this.tree,store);
|
||||||
renderSubTree(this.tree);
|
renderSubTree(this.tree);
|
||||||
return output.join("");
|
return output.join("");
|
||||||
};
|
};
|
||||||
|
@ -1 +1 @@
|
|||||||
An explicit link <a href="Fourth Tiddler">Fourth Tiddler</a> and <a href="Fourth Tiddler">a pretty link</a>
|
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"
|
@ -1,3 +1,3 @@
|
|||||||
title: ThirdTiddler
|
title: ThirdTiddler
|
||||||
|
|
||||||
An explicit link [[Fourth Tiddler]] and [[a pretty link|Fourth Tiddler]]
|
An explicit link [[Fourth Tiddler]] and [[a pretty link|Fourth Tiddler]] and a transclusion <<tiddler [[Fourth Tiddler]]>>
|
@ -1 +1 @@
|
|||||||
An explicit link Fourth Tiddler and a pretty link
|
An explicit link Fourth Tiddler and a pretty link and a transclusion An image and a couple of Ç Ç "HTML Entity"
|
@ -38,14 +38,14 @@ for(f=0; f<files.length; f++) {
|
|||||||
|
|
||||||
for(t=0; t<titles.length; t++) {
|
for(t=0; t<titles.length; t++) {
|
||||||
var tree = store.getTiddler(titles[t]).getParseTree(),
|
var tree = store.getTiddler(titles[t]).getParseTree(),
|
||||||
htmlRender = tree.render("text/html"),
|
htmlRender = tree.render("text/html",store,titles[t]),
|
||||||
htmlTarget = fs.readFileSync(path.resolve(testdirectory,titles[t] + ".html"),"utf8"),
|
htmlTarget = fs.readFileSync(path.resolve(testdirectory,titles[t] + ".html"),"utf8"),
|
||||||
plainRender = tree.render("text/plain"),
|
plainRender = tree.render("text/plain",store,titles[t]),
|
||||||
plainTarget = fs.readFileSync(path.resolve(testdirectory,titles[t] + ".txt"),"utf8");
|
plainTarget = fs.readFileSync(path.resolve(testdirectory,titles[t] + ".txt"),"utf8");
|
||||||
if(htmlTarget !== htmlRender) {
|
if(htmlTarget !== htmlRender) {
|
||||||
console.error("Tiddler %s html error\nTarget: %s\nFound: %s",titles[t],htmlTarget,htmlRender);
|
console.error("Tiddler %s html error\nTarget: %s\nFound: %s\n",titles[t],htmlTarget,htmlRender);
|
||||||
}
|
}
|
||||||
if(plainTarget !== plainRender) {
|
if(plainTarget !== plainRender) {
|
||||||
console.error("Tiddler %s plain text error\nTarget: %s\nFound: %s",titles[t],plainTarget,plainRender);
|
console.error("Tiddler %s plain text error\nTarget: %s\nFound: %s\n",titles[t],plainTarget,plainRender);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user