This commit is contained in:
Horis
2023-01-12 22:20:06 +08:00
parent 1893655ccb
commit e2ea6bd766
3 changed files with 7 additions and 3 deletions

View File

@@ -39,4 +39,6 @@ object AppPattern {
* 不发音段落判断
*/
val notReadAloudRegex = Regex("^(\\s|\\p{C}|\\p{P}|\\p{Z}|\\p{S})+$")
val xmlContentTypeRegex = "(application|text)/\\w*\\+?xml.*".toRegex()
}

View File

@@ -8,6 +8,7 @@ import com.bumptech.glide.load.model.GlideUrl
import com.script.SimpleBindings
import io.legado.app.constant.AppConst.SCRIPT_ENGINE
import io.legado.app.constant.AppConst.UA_NAME
import io.legado.app.constant.AppPattern
import io.legado.app.constant.AppPattern.JS_PATTERN
import io.legado.app.constant.AppPattern.dataUriRegex
import io.legado.app.data.entities.BaseSource
@@ -422,7 +423,7 @@ class AnalyzeUrl(
}
}.let {
val isXml = it.raw.body?.contentType()?.toString()
?.matches("(application|text)/\\w*\\+?xml.*".toRegex()) == true
?.matches(AppPattern.xmlContentTypeRegex) == true
if (isXml && it.body?.trim()?.startsWith("<?xml", true) == false) {
StrResponse(it.raw, "<?xml version=\"1.0\"?>" + it.body)
} else it

View File

@@ -190,7 +190,8 @@ class EpubFile(var book: Book) {
}
private fun getBody(res: Resource, startFragmentId: String?, endFragmentId: String?): Element {
val body = Jsoup.parse(String(res.data, mCharset)).body()
val doc = Jsoup.parse(String(res.data, mCharset))
val body = doc.body()
if (!startFragmentId.isNullOrBlank()) {
body.getElementById(startFragmentId)?.previousElementSiblings()?.remove()
}
@@ -215,7 +216,7 @@ class EpubFile(var book: Book) {
val children = body.children()
children.select("script").remove()
children.select("style").remove()
return body
return doc.body()
}
private fun getImage(href: String): InputStream? {