1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-12-25 01:20:30 +00:00

Added support for PDF images

This commit is contained in:
Jeremy Ruston 2012-10-10 10:45:39 +01:00
parent 59b00e88c0
commit fc19a77353
4 changed files with 26 additions and 5 deletions

View File

@ -81,6 +81,9 @@ $tw.modules = $tw.modules || {};
$tw.modules.titles = $tw.modules.titles || {}; // hashmap by module title of {fn:, exports:, moduleType:} $tw.modules.titles = $tw.modules.titles || {}; // hashmap by module title of {fn:, exports:, moduleType:}
$tw.modules.types = $tw.modules.types || {}; // hashmap by module type of array of exports $tw.modules.types = $tw.modules.types || {}; // hashmap by module type of array of exports
// Plugin information
$tw.plugins = $tw.plugins || {};
// Config object // Config object
$tw.config = $tw.config || {}; $tw.config = $tw.config || {};
@ -102,6 +105,7 @@ $tw.config.fileExtensionInfo = {
".html": {type: "text/html"}, ".html": {type: "text/html"},
".js": {type: "application/javascript"}, ".js": {type: "application/javascript"},
".json": {type: "application/json"}, ".json": {type: "application/json"},
".pdf": {type: "application/pdf"},
".jpg": {type: "image/jpeg"}, ".jpg": {type: "image/jpeg"},
".jpeg": {type: "image/jpeg"}, ".jpeg": {type: "image/jpeg"},
".png": {type: "image/png"}, ".png": {type: "image/png"},
@ -119,6 +123,7 @@ $tw.config.contentTypeInfo = {
"text/html": {encoding: "utf8"}, "text/html": {encoding: "utf8"},
"application/javascript": {encoding: "utf8"}, "application/javascript": {encoding: "utf8"},
"application/json": {encoding: "utf8"}, "application/json": {encoding: "utf8"},
"application/pdf": {encoding: "base64"},
"image/jpeg": {encoding: "base64"}, "image/jpeg": {encoding: "base64"},
"image/png": {encoding: "base64"}, "image/png": {encoding: "base64"},
"image/gif": {encoding: "base64"}, "image/gif": {encoding: "base64"},

View File

@ -17,13 +17,17 @@ var ImageParser = function(options) {
}; };
ImageParser.prototype.parse = function(type,text) { ImageParser.prototype.parse = function(type,text) {
var src; var element = "img",
if(type === "image/svg+xml" || type === ".svg") { 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); src = "data:image/svg+xml," + encodeURIComponent(text);
} else { } else {
src = "data:" + type + ";base64," + text; src = "data:" + type + ";base64," + text;
} }
return new $tw.Renderer([$tw.Tree.Element("img",{src: src})],new $tw.Dependencies()); return new $tw.Renderer([$tw.Tree.Element(element,{src: src})],new $tw.Dependencies());
}; };
exports["image/svg+xml"] = ImageParser; exports["image/svg+xml"] = ImageParser;
@ -31,5 +35,6 @@ exports["image/jpg"] = ImageParser;
exports["image/jpeg"] = ImageParser; exports["image/jpeg"] = ImageParser;
exports["image/png"] = ImageParser; exports["image/png"] = ImageParser;
exports["image/gif"] = ImageParser; exports["image/gif"] = ImageParser;
exports["application/pdf"] = ImageParser;
})(); })();

View File

@ -5103,10 +5103,16 @@ canvas.tw-edit-field {
} }
img, img,
canvas { canvas,
embed {
max-width: 100%; max-width: 100%;
} }
embed {
width: 100%;
height: 20em;
}
a.tw-tiddlylink { a.tw-tiddlylink {
font-style: normal; font-style: normal;
font-weight: normal; font-weight: normal;

View File

@ -119,10 +119,15 @@ canvas.tw-edit-field {
-ms-user-select: none; -ms-user-select: none;
} }
img, canvas { img, canvas, embed {
max-width: 100%; max-width: 100%;
} }
embed {
width: 100%;
height: 20em;
}
a.tw-tiddlylink { a.tw-tiddlylink {
font-style: normal; font-style: normal;
font-weight: normal; font-weight: normal;