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