From 7386d4ff9aea43294e670100edf80e790a3c5fce Mon Sep 17 00:00:00 2001 From: Julien Chaumond Date: Wed, 4 Dec 2013 17:26:03 +0100 Subject: [PATCH] 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