1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-17 15:24:50 +00:00

Get rid of the old WikiTextParseTree class

And replace it with a new root Renderer() class
This commit is contained in:
Jeremy Ruston 2012-03-03 18:33:16 +00:00
parent 26b5fc4a6d
commit 7f136dd898
7 changed files with 25 additions and 50 deletions

View File

@ -9,8 +9,7 @@ Compiles images into JavaScript functions that render them in HTML
/*jslint node: true */ /*jslint node: true */
"use strict"; "use strict";
var WikiTextParseTree = require("./WikiTextParseTree.js").WikiTextParseTree, var Renderer = require("./Renderer.js").Renderer,
Renderer = require("./Renderer.js").Renderer,
Dependencies = require("./Dependencies.js").Dependencies, Dependencies = require("./Dependencies.js").Dependencies,
utils = require("./Utils.js"); utils = require("./Utils.js");
@ -25,7 +24,7 @@ ImageParser.prototype.parse = function(type,text) {
} else { } else {
src = "data:" + type + ";base64," + text; src = "data:" + type + ";base64," + text;
} }
return new WikiTextParseTree([Renderer.ElementNode("img",{src: src})],new Dependencies(),this.store); return new Renderer([Renderer.ElementNode("img",{src: src})],new Dependencies(),this.store);
}; };
exports.ImageParser = ImageParser; exports.ImageParser = ImageParser;

View File

@ -9,8 +9,7 @@ Compiles JSON objects into JavaScript functions that render them in HTML and pla
/*jslint node: true */ /*jslint node: true */
"use strict"; "use strict";
var WikiTextParseTree = require("./WikiTextParseTree.js").WikiTextParseTree, var Renderer = require("./Renderer.js").Renderer,
Renderer = require("./Renderer.js").Renderer,
Dependencies = require("./Dependencies.js").Dependencies, Dependencies = require("./Dependencies.js").Dependencies,
utils = require("./Utils.js"); utils = require("./Utils.js");
@ -44,7 +43,7 @@ var JSONParser = function(options) {
}; };
JSONParser.prototype.parse = function(type,text) { JSONParser.prototype.parse = function(type,text) {
return new WikiTextParseTree([renderObject(JSON.parse(text))],new Dependencies(),this.store); return new Renderer([renderObject(JSON.parse(text))],new Dependencies(),this.store);
}; };
exports.JSONParser = JSONParser; exports.JSONParser = JSONParser;

View File

@ -9,8 +9,7 @@ Parses JavaScript source code into a parse tree using Esprima
/*jslint node: true */ /*jslint node: true */
"use strict"; "use strict";
var WikiTextParseTree = require("./WikiTextParseTree.js").WikiTextParseTree, var Renderer = require("./Renderer.js").Renderer,
Renderer = require("./Renderer.js").Renderer,
Dependencies = require("./Dependencies.js").Dependencies, Dependencies = require("./Dependencies.js").Dependencies,
esprima = require("esprima"); esprima = require("esprima");
@ -27,7 +26,7 @@ JavaScriptParser.prototype.parse = function(type,code) {
parseTree = esprima.parse(code,{comment: true,tokens: true,range: true}); parseTree = esprima.parse(code,{comment: true,tokens: true,range: true});
} catch(ex) { } catch(ex) {
// Return a helpful error if the parse failed // Return a helpful error if the parse failed
return new WikiTextParseTree([ return new Renderer([
Renderer.ElementNode("pre",{"class": "javascript-source"},[ Renderer.ElementNode("pre",{"class": "javascript-source"},[
Renderer.TextNode(code.substring(0,ex.index)), Renderer.TextNode(code.substring(0,ex.index)),
Renderer.ErrorNode(ex), Renderer.ErrorNode(ex),
@ -95,7 +94,7 @@ JavaScriptParser.prototype.parse = function(type,code) {
} }
renderWhitespace(code.length); renderWhitespace(code.length);
// Wrap the whole lot in a `<PRE>` // Wrap the whole lot in a `<PRE>`
return new WikiTextParseTree([ return new Renderer([
Renderer.ElementNode("pre",{"class": "javascript-source"},result) Renderer.ElementNode("pre",{"class": "javascript-source"},result)
],new Dependencies(),this.store); ],new Dependencies(),this.store);
}; };

View File

@ -9,8 +9,7 @@ Renders plain text tiddlers
/*jslint node: true */ /*jslint node: true */
"use strict"; "use strict";
var WikiTextParseTree = require("./WikiTextParseTree.js").WikiTextParseTree, var Renderer = require("./Renderer.js").Renderer,
Renderer = require("./Renderer.js").Renderer,
Dependencies = require("./Dependencies.js").Dependencies, Dependencies = require("./Dependencies.js").Dependencies,
utils = require("./Utils.js"); utils = require("./Utils.js");
@ -19,7 +18,7 @@ var PlainTextParser = function(options) {
}; };
PlainTextParser.prototype.parse = function(type,text) { PlainTextParser.prototype.parse = function(type,text) {
return new WikiTextParseTree([Renderer.ElementNode("pre",{},[Renderer.TextNode(text)])],new Dependencies(),this.store); return new Renderer([Renderer.ElementNode("pre",{},[Renderer.TextNode(text)])],new Dependencies(),this.store);
}; };
exports.PlainTextParser = PlainTextParser; exports.PlainTextParser = PlainTextParser;

View File

@ -14,6 +14,13 @@ var utils = require("./Utils.js"),
Dependencies = require("./Dependencies.js").Dependencies, Dependencies = require("./Dependencies.js").Dependencies,
esprima = require("esprima"); esprima = require("esprima");
// Intialise the renderer object
var Renderer = function(tree,dependencies,store) {
this.tree = tree;
this.dependencies = dependencies;
this.store = store;
};
var Node = function(children) { var Node = function(children) {
if(this instanceof Node) { if(this instanceof Node) {
this.children = children; this.children = children;
@ -498,16 +505,14 @@ var SliderNode = function(type,label,tooltip,isOpen,children) {
); );
}; };
var Renderer = { Renderer.MacroNode = MacroNode;
MacroNode: MacroNode, Renderer.ElementNode = ElementNode;
ElementNode: ElementNode, Renderer.TextNode = TextNode;
TextNode: TextNode, Renderer.EntityNode = EntityNode;
EntityNode: EntityNode, Renderer.ErrorNode = ErrorNode;
ErrorNode: ErrorNode, Renderer.LabelNode = LabelNode;
LabelNode: LabelNode, Renderer.SplitLabelNode = SplitLabelNode;
SplitLabelNode: SplitLabelNode, Renderer.SliderNode = SliderNode;
SliderNode: SliderNode
};
exports.Renderer = Renderer; exports.Renderer = Renderer;

View File

@ -1,25 +0,0 @@
/*\
title: js/WikiTextParseTree.js
A container for the parse tree generated by parsing wikitext
\*/
(function(){
/*jslint node: true */
"use strict";
var Renderer = require("./Renderer.js").Renderer,
ArgParser = require("./ArgParser.js").ArgParser,
utils = require("./Utils.js");
// Intialise the parse tree object
var WikiTextParseTree = function(tree,dependencies,store) {
this.tree = tree;
this.dependencies = dependencies;
this.store = store;
};
exports.WikiTextParseTree = WikiTextParseTree;
})();

View File

@ -32,7 +32,6 @@ HTML nodes look like this:
"use strict"; "use strict";
var WikiTextRules = require("./WikiTextRules.js"), var WikiTextRules = require("./WikiTextRules.js"),
WikiTextParseTree = require("./WikiTextParseTree.js").WikiTextParseTree,
Dependencies = require("./Dependencies.js").Dependencies, Dependencies = require("./Dependencies.js").Dependencies,
Renderer = require("./Renderer.js").Renderer, Renderer = require("./Renderer.js").Renderer,
utils = require("./Utils.js"), utils = require("./Utils.js"),
@ -71,7 +70,7 @@ WikiTextParser.prototype.parse = function(type,text) {
this.dependencies = new Dependencies(); this.dependencies = new Dependencies();
this.output = null; this.output = null;
this.subWikify(this.children); this.subWikify(this.children);
var tree = new WikiTextParseTree(this.children,this.dependencies,this.store); var tree = new Renderer(this.children,this.dependencies,this.store);
this.source = null; this.source = null;
this.children = null; this.children = null;
return tree; return tree;