feat: add BookOasis document reader and text settings
This commit is contained in:
@@ -34,6 +34,27 @@ class EpubReader(private val reader: ArchiveReader) : Closeable by reader {
|
||||
return getImagesFromPages(pages, ref)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns readable text for each spine document in reading order.
|
||||
*/
|
||||
fun getTextFromPages(): List<String> {
|
||||
val ref = getPackageHref()
|
||||
val doc = getPackageDocument(ref)
|
||||
val basePath = getParentDirectory(ref)
|
||||
return getPagesFromDocument(doc).mapNotNull { page ->
|
||||
val entryPath = resolveZipPath(basePath, page)
|
||||
getInputStream(entryPath)?.use { input ->
|
||||
val pageDoc = Jsoup.parse(input, null, "")
|
||||
pageDoc.select("br").append("\n")
|
||||
pageDoc.select("p,div,li,h1,h2,h3,h4,h5,h6,blockquote").append("\n")
|
||||
pageDoc.body()?.wholeText()
|
||||
?.replace(Regex("[ \\t]+\\n"), "\n")
|
||||
?.replace(Regex("\\n{3,}"), "\n\n")
|
||||
?.trim()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the path to the package document.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user