Refactor the image parser to avoid generating badly formed image src's

Previously, a transclusion of a skinny image tiddler (ie one where the
body has yet to be loaded) would render a broken image.
print-window-tiddler
Jermolene 2014-01-29 19:11:05 +00:00
rodzic 29c4ed20ce
commit 0c20092644
1 zmienionych plików z 15 dodań i 15 usunięć

Wyświetl plik

@ -13,23 +13,23 @@ The image parser parses an image into an embeddable HTML element
"use strict"; "use strict";
var ImageParser = function(type,text,options) { var ImageParser = function(type,text,options) {
var element = "img", var element = {
type: "element",
tag: "img",
attributes: {}
},
src; src;
if(type === "application/pdf" || type === ".pdf") { if(text) {
src = "data:application/pdf;base64," + text; if(type === "application/pdf" || type === ".pdf") {
element = "embed"; element.attributes.src = {type: "string", value: "data:application/pdf;base64," + text};
} else if(type === "image/svg+xml" || type === ".svg") { element.tag = "embed";
src = "data:image/svg+xml," + encodeURIComponent(text); } else if(type === "image/svg+xml" || type === ".svg") {
} else { element.attributes.src = {type: "string", value: "data:image/svg+xml," + encodeURIComponent(text)};
src = "data:" + type + ";base64," + text; } else {
} element.attributes.src = {type: "string", value: "data:" + type + ";base64," + text};
this.tree = [{
type: "element",
tag: element,
attributes: {
"src": {type: "string", value: src}
} }
}]; }
this.tree = [element];
}; };
exports["image/svg+xml"] = ImageParser; exports["image/svg+xml"] = ImageParser;