diff --git a/.gitignore b/.gitignore index b333c38..6f4cff7 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -*.epub \ No newline at end of file +*.epub +test.* \ No newline at end of file diff --git a/epub.js b/epub.js index cb94f13..248d57f 100644 --- a/epub.js +++ b/epub.js @@ -23,6 +23,16 @@ module.exports = EPub; * }); * epub.on("error", function(error){ ... }); * epub.parse(); + * + * Image and link URL format is: + * + * imageroot + img_id + img_zip_path + * + * So an image "logo.jpg" which resides in "OPT/" in the zip archive + * and is listed in the manifest with id "logo_img" will have the + * following url (providing that imageroot is "/images/"): + * + * /images/logo_img/OPT/logo.jpg **/ function EPub(fname, imageroot, linkroot){ EventEmitter.call(this); @@ -493,9 +503,27 @@ EPub.prototype.getChapter = function(id, callback){ var str = data.toString("utf-8"); - // strip - str.replace(/\n/g,"\u0000").replace(/]*?>(.*)<\/body[^>]*?>/i, function(o,d){ - str = d.replace(/\u0000/g,"\n").trim(); + // remove linebreaks (no multi line matches in JS regex!) + str = str.replace(/\r?\n/g,"\u0000"); + + // keep only contents + str.replace(/]*?>(.*)<\/body[^>]*?>/i, function(o,d){ + str = d.trim(); + }); + + // remove