1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-12-26 18:10:27 +00:00
TiddlyWiki5/core/modules/parsers/imageparser.js

41 lines
1.0 KiB
JavaScript
Raw Normal View History

/*\
title: $:/core/modules/parsers/imageparser.js
type: application/javascript
module-type: parser
Parses an image into a parse tree containing an HTML img element
\*/
(function(){
2012-05-04 17:49:04 +00:00
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
var ImageParser = function(options) {
this.wiki = options.wiki;
};
ImageParser.prototype.parse = function(type,text) {
2012-10-10 09:45:39 +00:00
var element = "img",
src;
if(type === "application/pdf" || type === ".pdf") {
src = "data:application/pdf;base64," + text;
element = "embed";
} else if(type === "image/svg+xml" || type === ".svg") {
src = "data:image/svg+xml," + encodeURIComponent(text);
} else {
src = "data:" + type + ";base64," + text;
}
2012-10-10 09:45:39 +00:00
return new $tw.Renderer([$tw.Tree.Element(element,{src: src})],new $tw.Dependencies());
};
exports["image/svg+xml"] = ImageParser;
exports["image/jpg"] = ImageParser;
exports["image/jpeg"] = ImageParser;
exports["image/png"] = ImageParser;
exports["image/gif"] = ImageParser;
2012-10-10 09:45:39 +00:00
exports["application/pdf"] = ImageParser;
})();