1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-27 12:07:19 +00:00

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.
This commit is contained in:
Jermolene 2014-01-29 19:11:05 +00:00
parent 29c4ed20ce
commit 0c20092644

View File

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