|
|
@ -9,9 +9,11 @@ import io.legado.app.data.entities.BookChapter |
|
|
|
import io.legado.app.help.BookHelp |
|
|
|
import io.legado.app.help.BookHelp |
|
|
|
import io.legado.app.utils.* |
|
|
|
import io.legado.app.utils.* |
|
|
|
import me.ag2s.epublib.domain.EpubBook |
|
|
|
import me.ag2s.epublib.domain.EpubBook |
|
|
|
|
|
|
|
import me.ag2s.epublib.domain.Resource |
|
|
|
import me.ag2s.epublib.domain.TOCReference |
|
|
|
import me.ag2s.epublib.domain.TOCReference |
|
|
|
import me.ag2s.epublib.epub.EpubReader |
|
|
|
import me.ag2s.epublib.epub.EpubReader |
|
|
|
import org.jsoup.Jsoup |
|
|
|
import org.jsoup.Jsoup |
|
|
|
|
|
|
|
import org.jsoup.nodes.Element |
|
|
|
import org.jsoup.select.Elements |
|
|
|
import org.jsoup.select.Elements |
|
|
|
import splitties.init.appCtx |
|
|
|
import splitties.init.appCtx |
|
|
|
import timber.log.Timber |
|
|
|
import timber.log.Timber |
|
|
@ -145,11 +147,26 @@ class EpubFile(var book: Book) { |
|
|
|
/*注:这里较大增加了内容加载的时间,所以首次获取内容后可存储到本地cache,减少重复加载*/ |
|
|
|
/*注:这里较大增加了内容加载的时间,所以首次获取内容后可存储到本地cache,减少重复加载*/ |
|
|
|
for (res in epubBook.contents) { |
|
|
|
for (res in epubBook.contents) { |
|
|
|
if (res.href == chapter.url) { |
|
|
|
if (res.href == chapter.url) { |
|
|
|
|
|
|
|
elements.add(getBody(res, startFragmentId, endFragmentId)) |
|
|
|
isChapter = true |
|
|
|
isChapter = true |
|
|
|
} else if (res.href == nextUrl) { |
|
|
|
} else if (isChapter) { |
|
|
|
|
|
|
|
if (nextUrl.isNullOrBlank() || res.href == nextUrl) { |
|
|
|
break |
|
|
|
break |
|
|
|
} |
|
|
|
} |
|
|
|
if (isChapter) { |
|
|
|
elements.add(getBody(res, startFragmentId, endFragmentId)) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
var html = elements.outerHtml() |
|
|
|
|
|
|
|
val tag = Book.rubyTag |
|
|
|
|
|
|
|
if (book.getDelTag(tag)) { |
|
|
|
|
|
|
|
html = html.replace("<ruby>\\s?([\\u4e00-\\u9fa5])\\s?.*?</ruby>".toRegex(), "$1") |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return HtmlFormatter.formatKeepImg(html) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return null |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private fun getBody(res: Resource, startFragmentId: String?, endFragmentId: String?): Element { |
|
|
|
val body = Jsoup.parse(String(res.data, mCharset)).body() |
|
|
|
val body = Jsoup.parse(String(res.data, mCharset)).body() |
|
|
|
if (!startFragmentId.isNullOrBlank()) { |
|
|
|
if (!startFragmentId.isNullOrBlank()) { |
|
|
|
body.getElementById(startFragmentId)?.previousElementSiblings()?.remove() |
|
|
|
body.getElementById(startFragmentId)?.previousElementSiblings()?.remove() |
|
|
@ -172,17 +189,7 @@ class EpubFile(var book: Book) { |
|
|
|
val children = body.children() |
|
|
|
val children = body.children() |
|
|
|
children.select("script").remove() |
|
|
|
children.select("script").remove() |
|
|
|
children.select("style").remove() |
|
|
|
children.select("style").remove() |
|
|
|
elements.add(body) |
|
|
|
return body |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
var html = elements.outerHtml() |
|
|
|
|
|
|
|
val tag = Book.rubyTag |
|
|
|
|
|
|
|
if (book.getDelTag(tag)) { |
|
|
|
|
|
|
|
html = html.replace("<ruby>\\s?([\\u4e00-\\u9fa5])\\s?.*?</ruby>".toRegex(), "$1") |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return HtmlFormatter.formatKeepImg(html) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return null |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private fun getImage(href: String): InputStream? { |
|
|
|
private fun getImage(href: String): InputStream? { |
|
|
|