From 18f50d4ba2c1d990ff1b2387f9b019cd388b445f Mon Sep 17 00:00:00 2001 From: Julien Chaumond Date: Tue, 3 Dec 2013 15:17:28 +0100 Subject: [PATCH 1/3] Add .gitignore --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2f6141d --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +node_modules +npm-debug.log +.DS_Store \ No newline at end of file From 7386d4ff9aea43294e670100edf80e790a3c5fce Mon Sep 17 00:00:00 2001 From: Julien Chaumond Date: Wed, 4 Dec 2013 17:26:03 +0100 Subject: [PATCH 2/3] Add ability to get any file from the Epub + access raw HTML content --- epub.js | 196 +++++++++++++++++++++++++++++++++----------------------- 1 file changed, 117 insertions(+), 79 deletions(-) diff --git a/epub.js b/epub.js index ecf66c5..90c7b7e 100644 --- a/epub.js +++ b/epub.js @@ -216,7 +216,7 @@ EPub.prototype.getRootFiles = function () { /** * EPub#handleRootFile() -> undefined * - * Parser the rootfile XML and calls rootfile parser + * Parses the rootfile XML and calls rootfile parser **/ EPub.prototype.handleRootFile = function () { @@ -527,13 +527,105 @@ EPub.prototype.walkNavMap = function (branch, path, id_list, level) { * etc. elements. Return only chapters with mime type application/xhtml+xml **/ EPub.prototype.getChapter = function (id, callback) { - var i, len, path = this.rootFile.split("/"), keys = Object.keys(this.manifest); - path.pop(); + this.getChapterRaw(id, (function (err, str) { + if (err) { + callback(err); + return; + } + var i, len, path = this.rootFile.split("/"), keys = Object.keys(this.manifest); + path.pop(); + + // 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