fixed whitespace
This commit is contained in:
parent
d8570d97a8
commit
43311b1868
45
epub.js
45
epub.js
@ -20,8 +20,8 @@ function EPub(fname, imageroot, linkroot){
|
|||||||
EventEmitter.call(this);
|
EventEmitter.call(this);
|
||||||
this.filename = fname;
|
this.filename = fname;
|
||||||
|
|
||||||
this.imageroot = (imageroot || "/images/").trim();
|
this.imageroot = (imageroot || "/images/").trim();
|
||||||
this.linkroot = (linkroot || "/links/").trim();
|
this.linkroot = (linkroot || "/links/").trim();
|
||||||
|
|
||||||
if(this.imageroot.substr(-1)!="/")this.imageroot+="/";
|
if(this.imageroot.substr(-1)!="/")this.imageroot+="/";
|
||||||
if(this.linkroot.substr(-1)!="/")this.linkroot+="/";
|
if(this.linkroot.substr(-1)!="/")this.linkroot+="/";
|
||||||
@ -269,53 +269,53 @@ EPub.prototype.parseMetadata = function(metadata){
|
|||||||
switch(key){
|
switch(key){
|
||||||
case "publisher":
|
case "publisher":
|
||||||
if(Array.isArray(metadata[keys[i]])){
|
if(Array.isArray(metadata[keys[i]])){
|
||||||
this.metadata.publisher = String(metadata[keys[i]][0] && metadata[keys[i]][0]["#"] || metadata[keys[i]][0] || "").trim();
|
this.metadata.publisher = String(metadata[keys[i]][0] && metadata[keys[i]][0]["#"] || metadata[keys[i]][0] || "").trim();
|
||||||
}else{
|
}else{
|
||||||
this.metadata.publisher = String(metadata[keys[i]]["#"] || metadata[keys[i]] || "").trim();
|
this.metadata.publisher = String(metadata[keys[i]]["#"] || metadata[keys[i]] || "").trim();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "language":
|
case "language":
|
||||||
if(Array.isArray(metadata[keys[i]])){
|
if(Array.isArray(metadata[keys[i]])){
|
||||||
this.metadata.language = String(metadata[keys[i]][0] && metadata[keys[i]][0]["#"] || metadata[keys[i]][0] || "").toLowerCase().trim();
|
this.metadata.language = String(metadata[keys[i]][0] && metadata[keys[i]][0]["#"] || metadata[keys[i]][0] || "").toLowerCase().trim();
|
||||||
}else{
|
}else{
|
||||||
this.metadata.language = String(metadata[keys[i]]["#"] || metadata[keys[i]] || "").toLowerCase().trim();
|
this.metadata.language = String(metadata[keys[i]]["#"] || metadata[keys[i]] || "").toLowerCase().trim();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "title":
|
case "title":
|
||||||
if(Array.isArray(metadata[keys[i]])){
|
if(Array.isArray(metadata[keys[i]])){
|
||||||
this.metadata.title = String(metadata[keys[i]][0] && metadata[keys[i]][0]["#"] || metadata[keys[i]][0] || "").trim();
|
this.metadata.title = String(metadata[keys[i]][0] && metadata[keys[i]][0]["#"] || metadata[keys[i]][0] || "").trim();
|
||||||
}else{
|
}else{
|
||||||
this.metadata.title = String(metadata[keys[i]]["#"] || metadata[keys[i]] || "").trim();
|
this.metadata.title = String(metadata[keys[i]]["#"] || metadata[keys[i]] || "").trim();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "subject":
|
case "subject":
|
||||||
if(Array.isArray(metadata[keys[i]])){
|
if(Array.isArray(metadata[keys[i]])){
|
||||||
this.metadata.subject = String(metadata[keys[i]][0] && metadata[keys[i]][0]["#"] || metadata[keys[i]][0] || "").trim();
|
this.metadata.subject = String(metadata[keys[i]][0] && metadata[keys[i]][0]["#"] || metadata[keys[i]][0] || "").trim();
|
||||||
}else{
|
}else{
|
||||||
this.metadata.subject = String(metadata[keys[i]]["#"] || metadata[keys[i]] || "").trim();
|
this.metadata.subject = String(metadata[keys[i]]["#"] || metadata[keys[i]] || "").trim();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "description":
|
case "description":
|
||||||
if(Array.isArray(metadata[keys[i]])){
|
if(Array.isArray(metadata[keys[i]])){
|
||||||
this.metadata.description = String(metadata[keys[i]][0] && metadata[keys[i]][0]["#"] || metadata[keys[i]][0] || "").trim();
|
this.metadata.description = String(metadata[keys[i]][0] && metadata[keys[i]][0]["#"] || metadata[keys[i]][0] || "").trim();
|
||||||
}else{
|
}else{
|
||||||
this.metadata.description = String(metadata[keys[i]]["#"] || metadata[keys[i]] || "").trim();
|
this.metadata.description = String(metadata[keys[i]]["#"] || metadata[keys[i]] || "").trim();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "creator":
|
case "creator":
|
||||||
if(Array.isArray(metadata[keys[i]])){
|
if(Array.isArray(metadata[keys[i]])){
|
||||||
this.metadata.creator = String(metadata[keys[i]][0] && metadata[keys[i]][0]["#"] || metadata[keys[i]][0] || "").trim();
|
this.metadata.creator = String(metadata[keys[i]][0] && metadata[keys[i]][0]["#"] || metadata[keys[i]][0] || "").trim();
|
||||||
this.metadata.creatorFileAs = String(metadata[keys[i]][0] && metadata[keys[i]][0]['@'] && metadata[keys[i]][0]['@']["opf:file-as"] || this.metadata.creator).trim();
|
this.metadata.creatorFileAs = String(metadata[keys[i]][0] && metadata[keys[i]][0]['@'] && metadata[keys[i]][0]['@']["opf:file-as"] || this.metadata.creator).trim();
|
||||||
}else{
|
}else{
|
||||||
this.metadata.creator = String(metadata[keys[i]]["#"] || metadata[keys[i]] || "").trim();
|
this.metadata.creator = String(metadata[keys[i]]["#"] || metadata[keys[i]] || "").trim();
|
||||||
this.metadata.creatorFileAs = String(metadata[keys[i]]['@'] && metadata[keys[i]]['@']["opf:file-as"] || this.metadata.creator).trim();
|
this.metadata.creatorFileAs = String(metadata[keys[i]]['@'] && metadata[keys[i]]['@']["opf:file-as"] || this.metadata.creator).trim();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "date":
|
case "date":
|
||||||
if(Array.isArray(metadata[keys[i]])){
|
if(Array.isArray(metadata[keys[i]])){
|
||||||
this.metadata.date = String(metadata[keys[i]][0] && metadata[keys[i]][0]["#"] || metadata[keys[i]][0] || "").trim();
|
this.metadata.date = String(metadata[keys[i]][0] && metadata[keys[i]][0]["#"] || metadata[keys[i]][0] || "").trim();
|
||||||
}else{
|
}else{
|
||||||
this.metadata.date = String(metadata[keys[i]]["#"] || metadata[keys[i]] || "").trim();
|
this.metadata.date = String(metadata[keys[i]]["#"] || metadata[keys[i]] || "").trim();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "identifier":
|
case "identifier":
|
||||||
@ -514,11 +514,9 @@ EPub.prototype.getChapter = function(id, callback){
|
|||||||
// replace links
|
// replace links
|
||||||
str = str.replace(/(\shref\s*=\s*["']?)([^"'\s>]*?)(["'\s>])/g, (function(o, a, b, c){
|
str = str.replace(/(\shref\s*=\s*["']?)([^"'\s>]*?)(["'\s>])/g, (function(o, a, b, c){
|
||||||
var linkparts = b && b.split("#"),
|
var linkparts = b && b.split("#"),
|
||||||
link = path.concat([(linkparts.shift() || "")]).join("/").trim(),
|
link = path.concat([(linkparts.shift() || "")]).join("/").trim(),
|
||||||
element;
|
element;
|
||||||
|
|
||||||
console.log(link, linkparts.join("#"));
|
|
||||||
|
|
||||||
for(var i=0, len=keys.length; i<len; i++){
|
for(var i=0, len=keys.length; i<len; i++){
|
||||||
if(this.manifest[keys[i]].href.split("#")[0] == link){
|
if(this.manifest[keys[i]].href.split("#")[0] == link){
|
||||||
element = this.manifest[keys[i]];
|
element = this.manifest[keys[i]];
|
||||||
@ -565,12 +563,3 @@ epub.on("end", function(err){
|
|||||||
|
|
||||||
epub.parse();
|
epub.parse();
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
for(var i=0, len = this.zip.names.length; i<len; i++){
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user