pull/2706/head
Horis 2 years ago
parent 1893655ccb
commit e2ea6bd766
  1. 2
      app/src/main/java/io/legado/app/constant/AppPattern.kt
  2. 3
      app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt
  3. 5
      app/src/main/java/io/legado/app/model/localBook/EpubFile.kt

@ -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()
}

@ -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

@ -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? {

Loading…
Cancel
Save