1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-09-29 23:40:45 +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 */
"use strict";
var WikiTextParseTree = require("./WikiTextParseTree.js").WikiTextParseTree,
Renderer = require("./Renderer.js").Renderer,
var Renderer = require("./Renderer.js").Renderer,
Dependencies = require("./Dependencies.js").Dependencies,
utils = require("./Utils.js");
@ -25,7 +24,7 @@ ImageParser.prototype.parse = function(type,text) {
} else {
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;

View File

@ -9,8 +9,7 @@ Compiles JSON objects into JavaScript functions that render them in HTML and pla
/*jslint node: true */
"use strict";
var WikiTextParseTree = require("./WikiTextParseTree.js").WikiTextParseTree,
Renderer = require("./Renderer.js").Renderer,
var Renderer = require("./Renderer.js").Renderer,
Dependencies = require("./Dependencies.js").Dependencies,
utils = require("./Utils.js");
@ -44,7 +43,7 @@ var JSONParser = function(options) {
};
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;

View File

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

View File

@ -9,8 +9,7 @@ Renders plain text tiddlers
/*jslint node: true */
"use strict";
var WikiTextParseTree = require("./WikiTextParseTree.js").WikiTextParseTree,
Renderer = require("./Renderer.js").Renderer,
var Renderer = require("./Renderer.js").Renderer,
Dependencies = require("./Dependencies.js").Dependencies,
utils = require("./Utils.js");
@ -19,7 +18,7 @@ var PlainTextParser = function(options) {
};
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;

View File

@ -14,6 +14,13 @@ var utils = require("./Utils.js"),
Dependencies = require("./Dependencies.js").Dependencies,
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) {
if(this instanceof Node) {
this.children = children;
@ -498,16 +505,14 @@ var SliderNode = function(type,label,tooltip,isOpen,children) {
);
};
var Renderer = {
MacroNode: MacroNode,
ElementNode: ElementNode,
TextNode: TextNode,
EntityNode: EntityNode,
ErrorNode: ErrorNode,
LabelNode: LabelNode,
SplitLabelNode: SplitLabelNode,
SliderNode: SliderNode
};
Renderer.MacroNode = MacroNode;
Renderer.ElementNode = ElementNode;
Renderer.TextNode = TextNode;
Renderer.EntityNode = EntityNode;
Renderer.ErrorNode = ErrorNode;
Renderer.LabelNode = LabelNode;
Renderer.SplitLabelNode = SplitLabelNode;
Renderer.SliderNode = SliderNode;
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";
var WikiTextRules = require("./WikiTextRules.js"),
WikiTextParseTree = require("./WikiTextParseTree.js").WikiTextParseTree,
Dependencies = require("./Dependencies.js").Dependencies,
Renderer = require("./Renderer.js").Renderer,
utils = require("./Utils.js"),
@ -71,7 +70,7 @@ WikiTextParser.prototype.parse = function(type,text) {
this.dependencies = new Dependencies();
this.output = null;
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.children = null;
return tree;