mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-12-28 02:50:27 +00:00
Added support for macros
And added a dummy version macro to get started
This commit is contained in:
parent
5b5bc2f756
commit
172d4cdcf2
40
js/WikiTextMacros.js
Normal file
40
js/WikiTextMacros.js
Normal file
@ -0,0 +1,40 @@
|
||||
/*
|
||||
Wiki text macro implementation
|
||||
*/
|
||||
|
||||
|
||||
/*global require: false, exports: false */
|
||||
"use strict";
|
||||
|
||||
var util = require("util");
|
||||
|
||||
var wikiTextMacros = exports;
|
||||
|
||||
wikiTextMacros.executeMacros = function(tree,store) {
|
||||
for(var t=0; t<tree.length; t++) {
|
||||
if(tree[t].type === "macro") {
|
||||
wikiTextMacros.executeMacro(tree[t],store);
|
||||
}
|
||||
if(tree[t].children) {
|
||||
wikiTextMacros.executeMacros(tree[t].children,store);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
wikiTextMacros.executeMacro = function(macroNode,store) {
|
||||
var macroInfo = wikiTextMacros.macros[macroNode.name];
|
||||
macroNode.output = [];
|
||||
if(macroInfo) {
|
||||
macroInfo.handler(macroNode,store);
|
||||
} else {
|
||||
macroNode.output.push({type: "text", value: "Unknown macro " + macroNode.name});
|
||||
}
|
||||
};
|
||||
|
||||
wikiTextMacros.macros = {
|
||||
version: {
|
||||
handler: function(macroNode,store) {
|
||||
macroNode.output.push({type: "text", value: "0.0.0"});
|
||||
}
|
||||
}
|
||||
};
|
@ -26,7 +26,8 @@ Text nodes are:
|
||||
/*global require: false, exports: false */
|
||||
"use strict";
|
||||
|
||||
var wikiTextRules = require("./WikiTextRules.js").wikiTextRules,
|
||||
var wikiTextMacros = require("./WikiTextMacros.js"),
|
||||
wikiTextRules = require("./WikiTextRules.js").wikiTextRules,
|
||||
utils = require("./Utils.js"),
|
||||
util = require("util");
|
||||
|
||||
@ -91,12 +92,16 @@ WikiTextParser.prototype.renderAsHtml = function(store,title) {
|
||||
case "img":
|
||||
renderElement(tree[t],true); // Self closing elements
|
||||
break;
|
||||
case "macro":
|
||||
renderSubTree(tree[t].output);
|
||||
break;
|
||||
default:
|
||||
renderElement(tree[t]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
wikiTextMacros.executeMacros(this.tree,this.store);
|
||||
renderSubTree(this.tree);
|
||||
return output.join("");
|
||||
};
|
||||
@ -117,6 +122,9 @@ WikiTextParser.prototype.renderAsText = function(store,title) {
|
||||
output.push(tree[t].value);
|
||||
}
|
||||
break;
|
||||
case "macro":
|
||||
renderSubTree(tree[t].output);
|
||||
break;
|
||||
}
|
||||
if(tree[t].children) {
|
||||
renderSubTree(tree[t].children);
|
||||
|
@ -1 +1 @@
|
||||
<h2>Heading</h2>This is the second tiddler. It has a list:<br /><ul><li> Item one</li><li> Item two</li><li> Item three</li></ul>And a <macro></macro> and a <span className="myClass">custom class</span><br />
|
||||
<h2>Heading</h2>This is the second tiddler. It has a list:<br /><ul><li> Item one</li><li> Item two</li><li> Item three</li></ul>And a macro invocation 0.0.0 and a <span className="myClass">custom class</span><br />
|
@ -5,4 +5,4 @@ This is the second tiddler. It has a list:
|
||||
* Item one
|
||||
* Item two
|
||||
* Item three
|
||||
And a <<macro invocation>> and a {{myClass{custom class}}}
|
||||
And a macro invocation <<version>> and a {{myClass{custom class}}}
|
||||
|
@ -1 +1 @@
|
||||
HeadingThis is the second tiddler. It has a list: Item one Item two Item threeAnd a and a custom class
|
||||
HeadingThis is the second tiddler. It has a list: Item one Item two Item threeAnd a macro invocation 0.0.0 and a custom class
|
Loading…
Reference in New Issue
Block a user