1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-09-02 22:42:46 +00:00
TiddlyWiki5/js/ImageParser.js
Jeremy Ruston 4ce479f693 Refactored the image and JSON parsers
Now they reuse the WikiTextParseTree
2012-02-11 20:12:25 +00:00

33 lines
732 B
JavaScript

/*\
title: js/ImageParser.js
Compiles images into JavaScript functions that render them in HTML
\*/
(function(){
/*jslint node: true */
"use strict";
var WikiTextParseTree = require("./WikiTextParseTree.js").WikiTextParseTree,
HTML = require("./HTML.js").HTML,
utils = require("./Utils.js");
var ImageParser = function(options) {
this.store = options.store;
};
ImageParser.prototype.parse = function(type,text) {
var src;
if(this.type === "image/svg+xml") {
src = "data:" + type + "," + encodeURIComponent(text);
} else {
src = "data:" + type + ";base64," + text;
}
return new WikiTextParseTree([HTML.elem("img",{src: src})],{},this.store);
};
exports.ImageParser = ImageParser;
})();