1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-10-01 08:20:46 +00:00

Added support for macros to HTML.js

This commit is contained in:
Jeremy Ruston 2012-02-06 12:55:38 +00:00
parent 5814e29416
commit 9dfa0f4edd
2 changed files with 32 additions and 21 deletions

View File

@ -99,6 +99,17 @@ HTML.raw = function(value) {
return {type: "raw", value: value}; return {type: "raw", value: value};
}; };
/*
Static method to construct a macro call
*/
HTML.macro = function(name,params,children,dependencies) {
var m = {type: "macro", name: name, params: params, dependencies: dependencies};
if(children) {
m.children = children;
}
return m;
};
/* /*
Static method to construct a split label Static method to construct a split label
*/ */

View File

@ -142,7 +142,7 @@ var parseMacroCall = function(w,name,paramString) {
} }
} }
w.addDependencies(dependencies); w.addDependencies(dependencies);
return {type: "macro", name: name, params: params, dependencies: dependencies}; return HTML.macro(name,params,null,dependencies);
}; };
var rules = [ var rules = [
@ -172,7 +172,7 @@ var rules = [
w.nextMatch += lookaheadMatch[0].length+1; w.nextMatch += lookaheadMatch[0].length+1;
} else { } else {
if(nextRowType != currRowType) { if(nextRowType != currRowType) {
rowContainer = {type: this.rowTypes[nextRowType], children: [], attributes: {}}; rowContainer = HTML.elem(this.rowTypes[nextRowType],{},[]);
table.children.push(rowContainer); table.children.push(rowContainer);
currRowType = nextRowType; currRowType = nextRowType;
} }
@ -465,11 +465,11 @@ var rules = [
this.lookaheadRegExp.lastIndex = w.matchStart; this.lookaheadRegExp.lastIndex = w.matchStart;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source); var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
if(lookaheadMatch && lookaheadMatch.index == w.matchStart) { if(lookaheadMatch && lookaheadMatch.index == w.matchStart) {
var e = {type: "macro", name: "link", params: { var e = HTML.macro("link",{
target: {type: "string", value: null} target: {type: "string", value: null}
}, },
children: [HTML.text("")], [HTML.text("")],
dependencies: []}, []),
text = lookaheadMatch[1]; text = lookaheadMatch[1];
if(lookaheadMatch[3]) { if(lookaheadMatch[3]) {
// Pretty bracketted link // Pretty bracketted link
@ -509,16 +509,14 @@ var rules = [
} }
} }
if(w.autoLinkWikiWords) { if(w.autoLinkWikiWords) {
var link = {type: "macro", name: "link", params: { var link = HTML.macro("link",{
target: {type: "string", value: w.matchText} target: {type: "string", value: w.matchText}
}, },
children: [{ [
type: "text", HTML.text(w.source.substring(w.matchStart,w.nextMatch))
value: w.source.substring(w.matchStart,w.nextMatch) ],[
}],
dependencies: [
w.matchText w.matchText
]}; ]);
w.addDependency(w.matchText); w.addDependency(w.matchText);
w.output.push(link); w.output.push(link);
} else { } else {
@ -532,13 +530,13 @@ var rules = [
match: textPrimitives.urlPattern, match: textPrimitives.urlPattern,
handler: function(w) handler: function(w)
{ {
var e = {type: "macro", name: "link", params: { var e = HTML.macro("link",{
target: {type: "string", value: w.matchText} target: {type: "string", value: w.matchText}
}, },[
children: [HTML.text(w.source.substring(w.matchStart,w.nextMatch))], HTML.text(w.source.substring(w.matchStart,w.nextMatch))
dependencies: [ ],[
w.matchText w.matchText
]}; ]);
w.addDependency(w.matchText); w.addDependency(w.matchText);
w.output.push(e); w.output.push(e);
} }
@ -553,12 +551,14 @@ var rules = [
{ {
this.lookaheadRegExp.lastIndex = w.matchStart; this.lookaheadRegExp.lastIndex = w.matchStart;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source), var lookaheadMatch = this.lookaheadRegExp.exec(w.source),
image = {type: "macro", name: "image", params: { image = HTML.macro("image",{
src: {type: "string", value: ""} src: {type: "string", value: ""}
}}, },[],[]),
link = {type: "macro", name: "link", params: { link = HTML.macro("link",{
target: {type: "string", value: ""} target: {type: "string", value: ""}
}, children: [image]}; },[
image
],[]);
if(lookaheadMatch && lookaheadMatch.index == w.matchStart) { if(lookaheadMatch && lookaheadMatch.index == w.matchStart) {
if(lookaheadMatch[1]) { if(lookaheadMatch[1]) {
image.params.alignment = {type: "string", value: "left"}; image.params.alignment = {type: "string", value: "left"};