2012-12-27 17:08:29 +00:00
|
|
|
/*\
|
|
|
|
title: $:/core/modules/parsers/imageparser.js
|
|
|
|
type: application/javascript
|
2013-01-16 13:56:11 +00:00
|
|
|
module-type: parser
|
2012-12-27 17:08:29 +00:00
|
|
|
|
|
|
|
The image parser parses an image into an embeddable HTML element
|
|
|
|
|
|
|
|
\*/
|
|
|
|
(function(){
|
|
|
|
|
|
|
|
/*jslint node: true, browser: true */
|
|
|
|
/*global $tw: false */
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
var ImageParser = function(type,text,options) {
|
2014-01-29 19:11:05 +00:00
|
|
|
var element = {
|
|
|
|
type: "element",
|
|
|
|
tag: "img",
|
|
|
|
attributes: {}
|
|
|
|
},
|
2012-12-27 17:08:29 +00:00
|
|
|
src;
|
2014-06-12 07:36:30 +00:00
|
|
|
if(options._canonical_uri) {
|
|
|
|
element.attributes.src = {type: "string", value: options._canonical_uri};
|
|
|
|
} else if(text) {
|
2016-12-08 16:42:53 +00:00
|
|
|
if(type === "image/svg+xml" || type === ".svg") {
|
2014-01-29 19:11:05 +00:00
|
|
|
element.attributes.src = {type: "string", value: "data:image/svg+xml," + encodeURIComponent(text)};
|
|
|
|
} else {
|
|
|
|
element.attributes.src = {type: "string", value: "data:" + type + ";base64," + text};
|
2012-12-27 17:08:29 +00:00
|
|
|
}
|
2014-01-29 19:11:05 +00:00
|
|
|
}
|
|
|
|
this.tree = [element];
|
2012-12-27 17:08:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
exports["image/svg+xml"] = ImageParser;
|
|
|
|
exports["image/jpg"] = ImageParser;
|
|
|
|
exports["image/jpeg"] = ImageParser;
|
|
|
|
exports["image/png"] = ImageParser;
|
|
|
|
exports["image/gif"] = ImageParser;
|
2013-12-24 09:07:25 +00:00
|
|
|
exports["image/x-icon"] = ImageParser;
|
2012-12-27 17:08:29 +00:00
|
|
|
|
|
|
|
})();
|
|
|
|
|