mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-07-07 04:24:22 +00:00
Switched over to the new HTML class
This commit is contained in:
parent
7ac85ebbbb
commit
00774c1a48
|
@ -14,6 +14,7 @@ WikiStore uses the .cache member of tiddlers to store the following information:
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var Tiddler = require("./Tiddler.js").Tiddler,
|
var Tiddler = require("./Tiddler.js").Tiddler,
|
||||||
|
HTML = require("./HTML.js").HTML,
|
||||||
utils = require("./Utils.js");
|
utils = require("./Utils.js");
|
||||||
|
|
||||||
/* Creates a new WikiStore object
|
/* Creates a new WikiStore object
|
||||||
|
@ -353,30 +354,30 @@ WikiStore.prototype.renderTiddler = function(targetType,title,templateTitle,opti
|
||||||
if(typeof templateTitle !== "string") {
|
if(typeof templateTitle !== "string") {
|
||||||
templateTitle = title;
|
templateTitle = title;
|
||||||
}
|
}
|
||||||
var stitcher = ((targetType === "text/html") && !options.noWrap && !this.disableHtmlWrapperNodes) ? utils.stitchElement : function(a,b,c) {return c.content;},
|
var noWrap = options.noWrap || this.disableHtmlWrapperNodes,
|
||||||
tiddler = this.getTiddler(title),
|
tiddler = this.getTiddler(title),
|
||||||
renderer = this.compileTiddler(templateTitle,targetType),
|
renderer = this.compileTiddler(templateTitle,targetType),
|
||||||
renditions = this.getCacheForTiddler(templateTitle,"renditions",function() {
|
renditions = this.getCacheForTiddler(templateTitle,"renditions",function() {
|
||||||
return {};
|
return {};
|
||||||
});
|
}),
|
||||||
|
template,
|
||||||
|
content;
|
||||||
if(tiddler) {
|
if(tiddler) {
|
||||||
if(title !== templateTitle) {
|
if(title !== templateTitle) {
|
||||||
var template = this.getTiddler(templateTitle);
|
template = this.getTiddler(templateTitle);
|
||||||
return stitcher("div",{
|
content = renderer.render(tiddler,this);
|
||||||
"data-tw-render-tiddler": title,
|
return noWrap ? content : HTML(HTML.elem("div",{
|
||||||
"data-tw-render-template": templateTitle
|
"data-tw-render-tiddler": title,
|
||||||
},{
|
"data-tw-render-template": templateTitle
|
||||||
content: renderer.render(tiddler,this)
|
},[HTML.raw(content)]),targetType);
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
if(!renditions[targetType]) {
|
if(!renditions[targetType]) {
|
||||||
renditions[targetType] = renderer.render(tiddler,this);
|
renditions[targetType] = renderer.render(tiddler,this);
|
||||||
}
|
}
|
||||||
return stitcher("div",{
|
content = renditions[targetType];
|
||||||
"data-tw-render-tiddler": title
|
return noWrap ? content : HTML(HTML.elem("div",{
|
||||||
},{
|
"data-tw-render-tiddler": title
|
||||||
content: renditions[targetType]
|
},[HTML.raw(content)]),targetType);
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -10,6 +10,7 @@ A container for the parse tree generated by parsing wikitext
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var WikiTextRenderer = require("./WikiTextRenderer.js").WikiTextRenderer,
|
var WikiTextRenderer = require("./WikiTextRenderer.js").WikiTextRenderer,
|
||||||
|
HTML = require("./HTML.js").HTML,
|
||||||
ArgParser = require("./ArgParser.js").ArgParser,
|
ArgParser = require("./ArgParser.js").ArgParser,
|
||||||
utils = require("./Utils.js");
|
utils = require("./Utils.js");
|
||||||
|
|
||||||
|
@ -172,10 +173,10 @@ WikiTextParseTree.prototype.compileMacroCall = function(output,renderer,type,nod
|
||||||
// Add the wrapper node
|
// Add the wrapper node
|
||||||
var wrapperTag = macro.wrapperTag || "div";
|
var wrapperTag = macro.wrapperTag || "div";
|
||||||
if(type === "text/html" && !this.store.disableHtmlWrapperNodes) {
|
if(type === "text/html" && !this.store.disableHtmlWrapperNodes) {
|
||||||
pushString(output,utils.stitchElement(wrapperTag,{
|
pushString(output,HTML(HTML.elem(wrapperTag,{
|
||||||
"data-tw-macro": name,
|
"data-tw-macro": name,
|
||||||
"data-tw-render-step": renderStepIndex
|
"data-tw-render-step": renderStepIndex
|
||||||
}));
|
})));
|
||||||
}
|
}
|
||||||
// Output the macro call
|
// Output the macro call
|
||||||
output.push({
|
output.push({
|
||||||
|
@ -204,9 +205,7 @@ WikiTextParseTree.prototype.compileMacroCall = function(output,renderer,type,nod
|
||||||
|
|
||||||
WikiTextParseTree.prototype.compileElementHtml = function(output,renderer,element,options) {
|
WikiTextParseTree.prototype.compileElementHtml = function(output,renderer,element,options) {
|
||||||
options = options || {};
|
options = options || {};
|
||||||
pushString(output,utils.stitchElement(element.type,element.attributes,{
|
pushString(output,HTML(HTML.elem(element.type,element.attributes)));
|
||||||
selfClosing: options.selfClosing
|
|
||||||
}));
|
|
||||||
if(!options.selfClosing) {
|
if(!options.selfClosing) {
|
||||||
if(element.children) {
|
if(element.children) {
|
||||||
this.compileSubTreeHtml(output,renderer,element.children);
|
this.compileSubTreeHtml(output,renderer,element.children);
|
||||||
|
@ -277,119 +276,100 @@ WikiTextParseTree.prototype.compileSubTreePlain = function(output,renderer,tree)
|
||||||
|
|
||||||
// Render the parse tree to a debugging string of the specified MIME type
|
// Render the parse tree to a debugging string of the specified MIME type
|
||||||
WikiTextParseTree.prototype.toString = function(type) {
|
WikiTextParseTree.prototype.toString = function(type) {
|
||||||
var output = [],
|
var renderNode,
|
||||||
htmlNodes = "a br hr table tr td th h1 h2 h3 h4 h5 h6 ul ol li dl dd dt blockquote pre img strong em u sup sub strike code span div".split(" "),
|
renderArray = function(tree) {
|
||||||
customTemplates = [
|
var children = [];
|
||||||
function(output,type,node) { // Text nodes
|
for(var t=0; t<tree.length; t++) {
|
||||||
if(node.type === "text") {
|
children.push(HTML.elem("li",{
|
||||||
output.push(utils.stitchElement("div",null,
|
"class": ["nodeWikiText"]
|
||||||
{classes: ["treeNode","splitLabel"]}));
|
},renderNode(tree[t])));
|
||||||
output.push(utils.stitchElement("span",{"data-tw-treenode-type": "text"},{
|
|
||||||
content: node.type,
|
|
||||||
classes: ["splitLabelLeft"]
|
|
||||||
}));
|
|
||||||
output.push(utils.stitchElement("span",null,{
|
|
||||||
content: utils.htmlEncode(node.value).replace(/\n/g,"<br>"),
|
|
||||||
classes: ["splitLabelRight"]
|
|
||||||
}));
|
|
||||||
output.push("</div>");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
},
|
|
||||||
function(output,type,node) { // Macro nodes
|
|
||||||
if(node.type === "macro") {
|
|
||||||
output.push(utils.stitchElement("span",
|
|
||||||
{"data-tw-treenode-type": "macro"},{
|
|
||||||
content: utils.htmlEncode(node.name),
|
|
||||||
classes: ["treeNode","label"]
|
|
||||||
}));
|
|
||||||
for(var f in node.params) {
|
|
||||||
output.push(utils.stitchElement("span",null,{
|
|
||||||
classes: ["splitLabel"]
|
|
||||||
}));
|
|
||||||
output.push(utils.stitchElement("span",{"data-tw-treenode-type": "param"},{
|
|
||||||
content: utils.htmlEncode(f),
|
|
||||||
classes: ["splitLabelLeft"]
|
|
||||||
}));
|
|
||||||
var v = node.params[f].value;
|
|
||||||
if(node.params[f].type === "string") {
|
|
||||||
v = '"' + utils.stringify(v) + '"';
|
|
||||||
} else if(node.params[f].type === "eval") {
|
|
||||||
v = "{{" + v + "}}";
|
|
||||||
}
|
|
||||||
output.push(utils.stitchElement("span",null,{
|
|
||||||
content: utils.htmlEncode(v),
|
|
||||||
classes: ["splitLabelRight"]
|
|
||||||
}));
|
|
||||||
output.push("</span>");
|
|
||||||
}
|
|
||||||
output.push(utils.stitchElement("span",null,
|
|
||||||
{classes: ["treeNode","splitLabel"]}));
|
|
||||||
output.push(utils.stitchElement("span",{"data-tw-treenode-type": "renderStepDependencies"},{
|
|
||||||
content: "dependencies",
|
|
||||||
classes: ["splitLabelLeft"]
|
|
||||||
}));
|
|
||||||
output.push(utils.stitchElement("span",null,{
|
|
||||||
content: utils.htmlEncode(node.dependencies === null ? "*" : node.dependencies.join(", ")),
|
|
||||||
classes: ["splitLabelRight"]
|
|
||||||
}));
|
|
||||||
output.push("</span>");
|
|
||||||
if(node.children) {
|
|
||||||
utils.renderObject(output,type,node.children,customTemplates);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
},
|
|
||||||
function(output,type,node) { // HTML nodes
|
|
||||||
if(htmlNodes.indexOf(node.type) !== -1) {
|
|
||||||
output.push(utils.stitchElement("span",
|
|
||||||
{"data-tw-treenode-type": "html"},{
|
|
||||||
content: node.type,
|
|
||||||
classes: ["treeNode","label"]
|
|
||||||
}));
|
|
||||||
for(var f in node.attributes) {
|
|
||||||
output.push(utils.stitchElement("span",null,{
|
|
||||||
classes: ["treeNode"]
|
|
||||||
}));
|
|
||||||
var v = node.attributes[f];
|
|
||||||
if(typeof v === "string") {
|
|
||||||
v = '"' + utils.stringify(v) + '"';
|
|
||||||
} else if(v instanceof Array) {
|
|
||||||
v = v.join("; ");
|
|
||||||
}
|
|
||||||
if(typeof v === "object") {
|
|
||||||
output.push(utils.stitchElement("span",null,{
|
|
||||||
classes: ["label"],
|
|
||||||
content: utils.htmlEncode(f)
|
|
||||||
}));
|
|
||||||
utils.renderObject(output,type,v);
|
|
||||||
} else {
|
|
||||||
output.push(utils.stitchElement("span",null,{
|
|
||||||
classes: ["splitLabel"],
|
|
||||||
content: utils.stitchElement("span",null,{
|
|
||||||
classes: ["splitLabelLeft"],
|
|
||||||
content: utils.htmlEncode(f)
|
|
||||||
}) + utils.stitchElement("span",null,{
|
|
||||||
classes: ["splitLabelRight"],
|
|
||||||
content: utils.htmlEncode(v)
|
|
||||||
})
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
output.push("</span>");
|
|
||||||
}
|
|
||||||
if(node.children) {
|
|
||||||
utils.renderObject(output,type,node.children,customTemplates);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
];
|
return HTML.elem("ul",{
|
||||||
utils.renderObject(output,type,this.tree,customTemplates);
|
"class": ["treeWikiText"]
|
||||||
return output.join("");
|
},children);
|
||||||
|
},
|
||||||
|
renderTextNode = function(node) {
|
||||||
|
return [HTML.splitLabel(
|
||||||
|
node.type,
|
||||||
|
[HTML.text(node.type)],
|
||||||
|
[HTML.raw(utils.htmlEncode(node.value).replace(/\n/g,"<br>"))],
|
||||||
|
["treeNode"]
|
||||||
|
)];
|
||||||
|
},
|
||||||
|
renderMacroNode = function(node) {
|
||||||
|
var params = [],
|
||||||
|
ret = [];
|
||||||
|
for(var p in node.params) {
|
||||||
|
var v = node.params[p].value;
|
||||||
|
if(node.params[p].type === "eval") {
|
||||||
|
v = "{{" + v + "}}";
|
||||||
|
}
|
||||||
|
params.push(HTML.splitLabel(
|
||||||
|
"param",
|
||||||
|
[HTML.text(p)],
|
||||||
|
[HTML.text(v)]
|
||||||
|
));
|
||||||
|
}
|
||||||
|
ret.push(HTML.splitLabel(
|
||||||
|
"macro",
|
||||||
|
[HTML.text(node.name)],
|
||||||
|
params,
|
||||||
|
["treeNode"]
|
||||||
|
));
|
||||||
|
ret.push(HTML.splitLabel(
|
||||||
|
"dependencies",
|
||||||
|
[HTML.text("Dependencies")],
|
||||||
|
[HTML.text(node.dependencies === null ? "*" : node.dependencies.join(", "))],
|
||||||
|
["treeNode"]
|
||||||
|
));
|
||||||
|
if(node.children) {
|
||||||
|
ret.push(renderArray(node.children));
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
},
|
||||||
|
renderHtmlNode = function(node) {
|
||||||
|
var attributes = [],
|
||||||
|
ret = [];
|
||||||
|
for(var a in node.attributes) {
|
||||||
|
var v = node.attributes[a];
|
||||||
|
if(typeof v === "string") {
|
||||||
|
v = v;
|
||||||
|
} else if(v instanceof Array) {
|
||||||
|
v = v.join("; ");
|
||||||
|
} else if(typeof v === "object") {
|
||||||
|
var o = [];
|
||||||
|
for(var n in v) {
|
||||||
|
o.push(n,":",v[n],";");
|
||||||
|
}
|
||||||
|
v = o.join("");
|
||||||
|
}
|
||||||
|
attributes.push(HTML.splitLabel(
|
||||||
|
"attribute",
|
||||||
|
[HTML.text(a)],
|
||||||
|
[HTML.text(v)]
|
||||||
|
));
|
||||||
|
}
|
||||||
|
ret.push(HTML.splitLabel(
|
||||||
|
"html",
|
||||||
|
[HTML.text(node.type)],
|
||||||
|
attributes,
|
||||||
|
["treeNode"]
|
||||||
|
));
|
||||||
|
if(node.children) {
|
||||||
|
ret.push(renderArray(node.children));
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
};
|
||||||
|
renderNode = function(node) {
|
||||||
|
if(node.type === "text") {
|
||||||
|
return renderTextNode(node);
|
||||||
|
} else if(node.type === "macro") {
|
||||||
|
return renderMacroNode(node);
|
||||||
|
} else {
|
||||||
|
return renderHtmlNode(node);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
return HTML(renderArray(this.tree),type);
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.WikiTextParseTree = WikiTextParseTree;
|
exports.WikiTextParseTree = WikiTextParseTree;
|
||||||
|
|
|
@ -9,7 +9,8 @@ An array of JavaScript functions that generate a specified representation of a p
|
||||||
/*jslint node: true */
|
/*jslint node: true */
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var utils = require("./Utils.js");
|
var HTML = require("./HTML.js").HTML,
|
||||||
|
utils = require("./Utils.js");
|
||||||
|
|
||||||
var WikiTextRenderer = function() {
|
var WikiTextRenderer = function() {
|
||||||
this.renderSteps = []; // Array of {step: n, dependencies: [],handler: function(tiddler,renderer,store,utils) {}}
|
this.renderSteps = []; // Array of {step: n, dependencies: [],handler: function(tiddler,renderer,store,utils) {}}
|
||||||
|
@ -59,51 +60,61 @@ WikiTextRenderer.prototype.rerender = function(node,changes,tiddler,store,render
|
||||||
};
|
};
|
||||||
|
|
||||||
WikiTextRenderer.prototype.toString = function(type) {
|
WikiTextRenderer.prototype.toString = function(type) {
|
||||||
var output = [],
|
var renderNode,
|
||||||
stitchSplitLabel = function(name,value) {
|
renderArray = function(tree) {
|
||||||
output.push(utils.stitchElement("span",null,
|
var children = [];
|
||||||
{classes: ["treeNode","splitLabel"]}));
|
for(var t=0; t<tree.length; t++) {
|
||||||
output.push(utils.stitchElement("span",null,{
|
children.push(HTML.elem("li",{
|
||||||
content: name,
|
"class": ["nodeWikiTextRenderer"]
|
||||||
classes: ["splitLabelLeft"]
|
},renderNode(tree[t])));
|
||||||
}));
|
|
||||||
output.push(utils.stitchElement("code",null,{
|
|
||||||
content: value,
|
|
||||||
classes: ["splitLabelRight"]
|
|
||||||
}));
|
|
||||||
output.push("</span>");
|
|
||||||
},
|
|
||||||
customTemplates = [
|
|
||||||
function(output,type,node) { // Rendering step
|
|
||||||
if(node.step !== undefined) {
|
|
||||||
output.push(utils.stitchElement("span",null,{
|
|
||||||
content: node.step.toString(),
|
|
||||||
classes: ["treeNode","label"]
|
|
||||||
}));
|
|
||||||
output.push(utils.stitchElement("span",null,{
|
|
||||||
content: node.type.toString(),
|
|
||||||
classes: ["treeNode","label"]
|
|
||||||
}));
|
|
||||||
stitchSplitLabel("dependencies",node.dependencies === null ? "*" : node.dependencies.join(", "));
|
|
||||||
if(node.macro) {
|
|
||||||
stitchSplitLabel("macro",utils.htmlEncode(node.macro.toString()));
|
|
||||||
}
|
|
||||||
if(node.params) {
|
|
||||||
stitchSplitLabel("params",utils.htmlEncode(node.params.toString()).replace(/\n/g,"<br>"));
|
|
||||||
}
|
|
||||||
if(node.content) {
|
|
||||||
stitchSplitLabel("content",utils.htmlEncode(node.content.toString()).replace(/\n/g,"<br>"));
|
|
||||||
}
|
|
||||||
if(node.handler) {
|
|
||||||
stitchSplitLabel("handler",utils.htmlEncode(node.handler.toString()).replace(/\n/g,"<br>"));
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
];
|
return HTML.elem("ul",{
|
||||||
utils.renderObject(output,type,this.renderSteps,customTemplates);
|
"class": ["treeWikiTextRenderer"]
|
||||||
return output.join("");
|
},children);
|
||||||
|
};
|
||||||
|
renderNode = function(node) {
|
||||||
|
var ret = [];
|
||||||
|
ret.push(HTML.splitLabel(
|
||||||
|
"rendererStep",
|
||||||
|
[HTML.text(node.step.toString())],
|
||||||
|
[HTML.text(node.type.toString())]
|
||||||
|
));
|
||||||
|
ret.push(HTML.splitLabel(
|
||||||
|
"dependencies",
|
||||||
|
[HTML.text("Dependencies")],
|
||||||
|
[HTML.text(node.dependencies === null ? "*" : node.dependencies.join(", "))]
|
||||||
|
));
|
||||||
|
if(node.macro) {
|
||||||
|
ret.push(HTML.splitLabel(
|
||||||
|
"macro",
|
||||||
|
[HTML.text("macro")],
|
||||||
|
[HTML.text(node.macro)]
|
||||||
|
));
|
||||||
|
}
|
||||||
|
if(node.params) {
|
||||||
|
ret.push(HTML.splitLabel(
|
||||||
|
"params",
|
||||||
|
[HTML.text("params")],
|
||||||
|
[HTML.raw(utils.htmlEncode(node.params.toString()).replace(/\n/g,"<br>"))]
|
||||||
|
));
|
||||||
|
}
|
||||||
|
if(node.content) {
|
||||||
|
ret.push(HTML.splitLabel(
|
||||||
|
"content",
|
||||||
|
[HTML.text("content")],
|
||||||
|
[HTML.raw(utils.htmlEncode(node.content.toString()).replace(/\n/g,"<br>"))]
|
||||||
|
));
|
||||||
|
}
|
||||||
|
if(node.handler) {
|
||||||
|
ret.push(HTML.splitLabel(
|
||||||
|
"handler",
|
||||||
|
[HTML.text("handler")],
|
||||||
|
[HTML.raw(utils.htmlEncode(node.handler.toString()).replace(/\n/g,"<br>"))]
|
||||||
|
));
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
};
|
||||||
|
return HTML(renderArray(this.renderSteps),type);
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.WikiTextRenderer = WikiTextRenderer;
|
exports.WikiTextRenderer = WikiTextRenderer;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user