diff --git a/js/App.js b/js/App.js index 4e788bd09..081a0d97d 100644 --- a/js/App.js +++ b/js/App.js @@ -16,6 +16,7 @@ var WikiStore = require("./WikiStore.js").WikiStore, Renderer = require("./Renderer.js").Renderer, WikiTextParser = require("./WikiTextParser.js").WikiTextParser, JavaScriptParser = require("./JavaScriptParser.js").JavaScriptParser, + JSONParser = require("./JSONParser.js").JSONParser, ImageParser = require("./ImageParser.js").ImageParser; var App = function() { @@ -27,7 +28,8 @@ var App = function() { // Register the parsers this.store.registerParser("text/x-tiddlywiki",new WikiTextParser({store: this.store})); this.store.registerParser(["image/svg+xml","image/jpg","image/jpeg","image/png","image/gif"],new ImageParser({store: this.store})); - this.store.registerParser(["application/json","application/javascript"],new JavaScriptParser({store: this.store})); + this.store.registerParser("application/javascript",new JavaScriptParser({store: this.store})); + this.store.registerParser("application/json",new JSONParser({store: this.store})); // Register the standard tiddler serializers and deserializers tiddlerInput.register(this.store); tiddlerOutput.register(this.store); diff --git a/js/JSONParser.js b/js/JSONParser.js new file mode 100644 index 000000000..95f078fb9 --- /dev/null +++ b/js/JSONParser.js @@ -0,0 +1,52 @@ +/*\ +title: js/JSONParser.js + +Compiles JSON objects into JavaScript functions that render them in HTML and plain text + +\*/ +(function(){ + +/*jslint node: true */ +"use strict"; + +var WikiTextParseTree = require("./WikiTextParseTree.js").WikiTextParseTree, + Renderer = require("./Renderer.js").Renderer, + Dependencies = require("./Dependencies.js").Dependencies, + utils = require("./Utils.js"); + +var renderObject = function(obj) { + var children = [],t; + if(obj instanceof Array) { + for(t=0; t