feat: add BookOasis document reader and text settings
Build & Test / Build & Test App (push) Has been cancelled
Update website / update_website (release) Has been cancelled

This commit is contained in:
2026-09-19 10:58:14 +09:00
parent 5848ffb4c4
commit 4900efbca5
20 changed files with 746 additions and 7 deletions
@@ -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.
*/