mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-01-12 10:20:26 +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";
|
||||
|
||||
var Tiddler = require("./Tiddler.js").Tiddler,
|
||||
HTML = require("./HTML.js").HTML,
|
||||
utils = require("./Utils.js");
|
||||
|
||||
/* Creates a new WikiStore object
|
||||
@ -353,30 +354,30 @@ WikiStore.prototype.renderTiddler = function(targetType,title,templateTitle,opti
|
||||
if(typeof templateTitle !== "string") {
|
||||
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),
|
||||
renderer = this.compileTiddler(templateTitle,targetType),
|
||||
renditions = this.getCacheForTiddler(templateTitle,"renditions",function() {
|
||||
return {};
|
||||
});
|
||||
}),
|
||||
template,
|
||||
content;
|
||||
if(tiddler) {
|
||||
if(title !== templateTitle) {
|
||||
var template = this.getTiddler(templateTitle);
|
||||
return stitcher("div",{
|
||||
template = this.getTiddler(templateTitle);
|
||||
content = renderer.render(tiddler,this);
|
||||
return noWrap ? content : HTML(HTML.elem("div",{
|
||||
"data-tw-render-tiddler": title,
|
||||
"data-tw-render-template": templateTitle
|
||||
},{
|
||||
content: renderer.render(tiddler,this)
|
||||
});
|
||||
},[HTML.raw(content)]),targetType);
|
||||
} else {
|
||||
if(!renditions[targetType]) {
|
||||
renditions[targetType] = renderer.render(tiddler,this);
|
||||
}
|
||||
return stitcher("div",{
|
||||
content = renditions[targetType];
|
||||
return noWrap ? content : HTML(HTML.elem("div",{
|
||||
"data-tw-render-tiddler": title
|
||||
},{
|
||||
content: renditions[targetType]
|
||||
});
|
||||
},[HTML.raw(content)]),targetType);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
@ -10,6 +10,7 @@ A container for the parse tree generated by parsing wikitext
|
||||
"use strict";
|
||||
|
||||
var WikiTextRenderer = require("./WikiTextRenderer.js").WikiTextRenderer,
|
||||
HTML = require("./HTML.js").HTML,
|
||||
ArgParser = require("./ArgParser.js").ArgParser,
|
||||
utils = require("./Utils.js");
|
||||
|
||||
@ -172,10 +173,10 @@ WikiTextParseTree.prototype.compileMacroCall = function(output,renderer,type,nod
|
||||
// Add the wrapper node
|
||||
var wrapperTag = macro.wrapperTag || "div";
|
||||
if(type === "text/html" && !this.store.disableHtmlWrapperNodes) {
|
||||
pushString(output,utils.stitchElement(wrapperTag,{
|
||||
pushString(output,HTML(HTML.elem(wrapperTag,{
|
||||
"data-tw-macro": name,
|
||||
"data-tw-render-step": renderStepIndex
|
||||
}));
|
||||
})));
|
||||
}
|
||||
// Output the macro call
|
||||
output.push({
|
||||
@ -204,9 +205,7 @@ WikiTextParseTree.prototype.compileMacroCall = function(output,renderer,type,nod
|
||||
|
||||
WikiTextParseTree.prototype.compileElementHtml = function(output,renderer,element,options) {
|
||||
options = options || {};
|
||||
pushString(output,utils.stitchElement(element.type,element.attributes,{
|
||||
selfClosing: options.selfClosing
|
||||
}));
|
||||
pushString(output,HTML(HTML.elem(element.type,element.attributes)));
|
||||
if(!options.selfClosing) {
|
||||
if(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
|
||||
WikiTextParseTree.prototype.toString = function(type) {
|
||||
var output = [],
|
||||
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(" "),
|
||||
customTemplates = [
|
||||
function(output,type,node) { // Text nodes
|
||||
if(node.type === "text") {
|
||||
output.push(utils.stitchElement("div",null,
|
||||
{classes: ["treeNode","splitLabel"]}));
|
||||
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;
|
||||
var renderNode,
|
||||
renderArray = function(tree) {
|
||||
var children = [];
|
||||
for(var t=0; t<tree.length; t++) {
|
||||
children.push(HTML.elem("li",{
|
||||
"class": ["nodeWikiText"]
|
||||
},renderNode(tree[t])));
|
||||
}
|
||||
return false;
|
||||
return HTML.elem("ul",{
|
||||
"class": ["treeWikiText"]
|
||||
},children);
|
||||
},
|
||||
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") {
|
||||
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 + "}}";
|
||||
}
|
||||
output.push(utils.stitchElement("span",null,{
|
||||
content: utils.htmlEncode(v),
|
||||
classes: ["splitLabelRight"]
|
||||
}));
|
||||
output.push("</span>");
|
||||
params.push(HTML.splitLabel(
|
||||
"param",
|
||||
[HTML.text(p)],
|
||||
[HTML.text(v)]
|
||||
));
|
||||
}
|
||||
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>");
|
||||
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) {
|
||||
utils.renderObject(output,type,node.children,customTemplates);
|
||||
ret.push(renderArray(node.children));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return ret;
|
||||
},
|
||||
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];
|
||||
renderHtmlNode = function(node) {
|
||||
var attributes = [],
|
||||
ret = [];
|
||||
for(var a in node.attributes) {
|
||||
var v = node.attributes[a];
|
||||
if(typeof v === "string") {
|
||||
v = '"' + utils.stringify(v) + '"';
|
||||
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],";");
|
||||
}
|
||||
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)
|
||||
})
|
||||
}));
|
||||
v = o.join("");
|
||||
}
|
||||
output.push("</span>");
|
||||
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) {
|
||||
utils.renderObject(output,type,node.children,customTemplates);
|
||||
ret.push(renderArray(node.children));
|
||||
}
|
||||
return true;
|
||||
return ret;
|
||||
};
|
||||
renderNode = function(node) {
|
||||
if(node.type === "text") {
|
||||
return renderTextNode(node);
|
||||
} else if(node.type === "macro") {
|
||||
return renderMacroNode(node);
|
||||
} else {
|
||||
return false;
|
||||
return renderHtmlNode(node);
|
||||
}
|
||||
}
|
||||
];
|
||||
utils.renderObject(output,type,this.tree,customTemplates);
|
||||
return output.join("");
|
||||
};
|
||||
return HTML(renderArray(this.tree),type);
|
||||
};
|
||||
|
||||
exports.WikiTextParseTree = WikiTextParseTree;
|
||||
|
@ -9,7 +9,8 @@ An array of JavaScript functions that generate a specified representation of a p
|
||||
/*jslint node: true */
|
||||
"use strict";
|
||||
|
||||
var utils = require("./Utils.js");
|
||||
var HTML = require("./HTML.js").HTML,
|
||||
utils = require("./Utils.js");
|
||||
|
||||
var WikiTextRenderer = function() {
|
||||
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) {
|
||||
var output = [],
|
||||
stitchSplitLabel = function(name,value) {
|
||||
output.push(utils.stitchElement("span",null,
|
||||
{classes: ["treeNode","splitLabel"]}));
|
||||
output.push(utils.stitchElement("span",null,{
|
||||
content: name,
|
||||
classes: ["splitLabelLeft"]
|
||||
}));
|
||||
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(", "));
|
||||
var renderNode,
|
||||
renderArray = function(tree) {
|
||||
var children = [];
|
||||
for(var t=0; t<tree.length; t++) {
|
||||
children.push(HTML.elem("li",{
|
||||
"class": ["nodeWikiTextRenderer"]
|
||||
},renderNode(tree[t])));
|
||||
}
|
||||
return HTML.elem("ul",{
|
||||
"class": ["treeWikiTextRenderer"]
|
||||
},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) {
|
||||
stitchSplitLabel("macro",utils.htmlEncode(node.macro.toString()));
|
||||
ret.push(HTML.splitLabel(
|
||||
"macro",
|
||||
[HTML.text("macro")],
|
||||
[HTML.text(node.macro)]
|
||||
));
|
||||
}
|
||||
if(node.params) {
|
||||
stitchSplitLabel("params",utils.htmlEncode(node.params.toString()).replace(/\n/g,"<br>"));
|
||||
ret.push(HTML.splitLabel(
|
||||
"params",
|
||||
[HTML.text("params")],
|
||||
[HTML.raw(utils.htmlEncode(node.params.toString()).replace(/\n/g,"<br>"))]
|
||||
));
|
||||
}
|
||||
if(node.content) {
|
||||
stitchSplitLabel("content",utils.htmlEncode(node.content.toString()).replace(/\n/g,"<br>"));
|
||||
ret.push(HTML.splitLabel(
|
||||
"content",
|
||||
[HTML.text("content")],
|
||||
[HTML.raw(utils.htmlEncode(node.content.toString()).replace(/\n/g,"<br>"))]
|
||||
));
|
||||
}
|
||||
if(node.handler) {
|
||||
stitchSplitLabel("handler",utils.htmlEncode(node.handler.toString()).replace(/\n/g,"<br>"));
|
||||
ret.push(HTML.splitLabel(
|
||||
"handler",
|
||||
[HTML.text("handler")],
|
||||
[HTML.raw(utils.htmlEncode(node.handler.toString()).replace(/\n/g,"<br>"))]
|
||||
));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
];
|
||||
utils.renderObject(output,type,this.renderSteps,customTemplates);
|
||||
return output.join("");
|
||||
return ret;
|
||||
};
|
||||
return HTML(renderArray(this.renderSteps),type);
|
||||
};
|
||||
|
||||
exports.WikiTextRenderer = WikiTextRenderer;
|
||||
|
Loading…
Reference in New Issue
Block a user