mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-03-22 11:26:56 +00:00
Separate the PDF parser from the image parser
It was a bit of a hack, and made it harder to customise PDF presentation
This commit is contained in:
parent
25b2e846ce
commit
74def9e080
@ -21,14 +21,8 @@ var ImageParser = function(type,text,options) {
|
||||
src;
|
||||
if(options._canonical_uri) {
|
||||
element.attributes.src = {type: "string", value: options._canonical_uri};
|
||||
if(type === "application/pdf" || type === ".pdf") {
|
||||
element.tag = "embed";
|
||||
}
|
||||
} else 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") {
|
||||
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};
|
||||
@ -42,7 +36,6 @@ exports["image/jpg"] = ImageParser;
|
||||
exports["image/jpeg"] = ImageParser;
|
||||
exports["image/png"] = ImageParser;
|
||||
exports["image/gif"] = ImageParser;
|
||||
exports["application/pdf"] = ImageParser;
|
||||
exports["image/x-icon"] = ImageParser;
|
||||
|
||||
})();
|
||||
|
33
core/modules/parsers/pdfparser.js
Normal file
33
core/modules/parsers/pdfparser.js
Normal file
@ -0,0 +1,33 @@
|
||||
/*\
|
||||
title: $:/core/modules/parsers/pdfparser.js
|
||||
type: application/javascript
|
||||
module-type: parser
|
||||
|
||||
The PDF parser embeds a PDF viewer
|
||||
|
||||
\*/
|
||||
(function(){
|
||||
|
||||
/*jslint node: true, browser: true */
|
||||
/*global $tw: false */
|
||||
"use strict";
|
||||
|
||||
var ImageParser = function(type,text,options) {
|
||||
var element = {
|
||||
type: "element",
|
||||
tag: "embed",
|
||||
attributes: {}
|
||||
},
|
||||
src;
|
||||
if(options._canonical_uri) {
|
||||
element.attributes.src = {type: "string", value: options._canonical_uri};
|
||||
} else if(text) {
|
||||
element.attributes.src = {type: "string", value: "data:application/pdf;base64," + text};
|
||||
}
|
||||
this.tree = [element];
|
||||
};
|
||||
|
||||
exports["application/pdf"] = ImageParser;
|
||||
|
||||
})();
|
||||
|
Loading…
x
Reference in New Issue
Block a user