-
Notifications
You must be signed in to change notification settings - Fork 189
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
David Bashford
committed
Aug 3, 2018
1 parent
b27de26
commit 8951230
Showing
6 changed files
with
113 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
var EPub = require( 'epub2/node' ) | ||
, htmlExtract = require( './html' ) | ||
; | ||
|
||
function extractText( filePath, options, cb ) { | ||
var epub = new EPub( filePath ) | ||
, allText = '' | ||
, hasError = false | ||
, chapterCount = 0 | ||
; | ||
|
||
epub.on( 'end', function() { | ||
// Iterate over each chapter... | ||
epub.flow.forEach( function( chapter ) { | ||
// if already error, don't do anything | ||
if ( !hasError ) { | ||
// Get the chapter text | ||
epub.getChapterRaw( chapter.id, function( rawChaperError, text ) { | ||
if ( rawChaperError ) { | ||
hasError = true; | ||
cb( rawChaperError, null ); | ||
} else { | ||
// Extract the raw text from the chapter text (it's html) | ||
htmlExtract.extractFromText( text, options, function( htmlExtractError, outText ) { | ||
if ( htmlExtractError ) { | ||
hasError = true; | ||
cb( htmlExtractError, null ); | ||
} else { | ||
allText += outText; | ||
chapterCount++; | ||
if ( chapterCount === epub.flow.length ) { | ||
cb( null, allText ); | ||
} | ||
} | ||
}); | ||
} | ||
}); | ||
} | ||
}); | ||
}); | ||
|
||
epub.parse(); | ||
} | ||
|
||
module.exports = { | ||
types: ['application/epub+zip'], | ||
extract: extractText | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters