优化
This commit is contained in:
@@ -201,11 +201,18 @@ class AnalyzeRule(
|
|||||||
return getString(ruleList, mContent, isUrl)
|
return getString(ruleList, mContent, isUrl)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun getString(ruleStr: String?, unescape: Boolean): String {
|
||||||
|
if (TextUtils.isEmpty(ruleStr)) return ""
|
||||||
|
val ruleList = splitSourceRule(ruleStr)
|
||||||
|
return getString(ruleList, unescape = unescape)
|
||||||
|
}
|
||||||
|
|
||||||
@JvmOverloads
|
@JvmOverloads
|
||||||
fun getString(
|
fun getString(
|
||||||
ruleList: List<SourceRule>,
|
ruleList: List<SourceRule>,
|
||||||
mContent: Any? = null,
|
mContent: Any? = null,
|
||||||
isUrl: Boolean = false
|
isUrl: Boolean = false,
|
||||||
|
unescape: Boolean = true
|
||||||
): String {
|
): String {
|
||||||
var result: Any? = null
|
var result: Any? = null
|
||||||
val content = mContent ?: this.content
|
val content = mContent ?: this.content
|
||||||
@@ -239,13 +246,15 @@ class AnalyzeRule(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (result == null) result = ""
|
if (result == null) result = ""
|
||||||
val str = kotlin.runCatching {
|
val str = if (unescape) {
|
||||||
Entities.unescape(result.toString())
|
kotlin.runCatching {
|
||||||
}.onFailure {
|
Entities.unescape(result.toString())
|
||||||
log("Entities.unescape() error\n${it.localizedMessage}")
|
}.onFailure {
|
||||||
}.getOrElse {
|
log("Entities.unescape() error\n${it.localizedMessage}")
|
||||||
result.toString()
|
}.getOrElse {
|
||||||
}
|
result.toString()
|
||||||
|
}
|
||||||
|
} else result.toString()
|
||||||
if (isUrl) {
|
if (isUrl) {
|
||||||
return if (str.isBlank()) {
|
return if (str.isBlank()) {
|
||||||
baseUrl ?: ""
|
baseUrl ?: ""
|
||||||
|
|||||||
@@ -150,7 +150,7 @@ object BookContent {
|
|||||||
val nextUrlList = arrayListOf<String>()
|
val nextUrlList = arrayListOf<String>()
|
||||||
analyzeRule.chapter = chapter
|
analyzeRule.chapter = chapter
|
||||||
//获取正文
|
//获取正文
|
||||||
var content = analyzeRule.getString(contentRule.content)
|
var content = analyzeRule.getString(contentRule.content, unescape = false)
|
||||||
content = HtmlFormatter.formatKeepImg(content, rUrl)
|
content = HtmlFormatter.formatKeepImg(content, rUrl)
|
||||||
//获取下一页链接
|
//获取下一页链接
|
||||||
val nextUrlRule = contentRule.nextContentUrl
|
val nextUrlRule = contentRule.nextContentUrl
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package io.legado.app.utils
|
package io.legado.app.utils
|
||||||
|
|
||||||
|
import io.legado.app.constant.AppLog
|
||||||
import io.legado.app.model.analyzeRule.AnalyzeUrl
|
import io.legado.app.model.analyzeRule.AnalyzeUrl
|
||||||
|
import org.jsoup.nodes.Entities
|
||||||
import java.net.URL
|
import java.net.URL
|
||||||
import java.util.regex.Pattern
|
import java.util.regex.Pattern
|
||||||
|
|
||||||
@@ -29,6 +31,13 @@ object HtmlFormatter {
|
|||||||
.replace("\\s*\\n+\\s*".toRegex(), "\n ")
|
.replace("\\s*\\n+\\s*".toRegex(), "\n ")
|
||||||
.replace("^[\\n\\s]+".toRegex(), " ")
|
.replace("^[\\n\\s]+".toRegex(), " ")
|
||||||
.replace("[\\n\\s]+$".toRegex(), "")
|
.replace("[\\n\\s]+$".toRegex(), "")
|
||||||
|
.let { s ->
|
||||||
|
kotlin.runCatching {
|
||||||
|
Entities.unescape(s)
|
||||||
|
}.onFailure {
|
||||||
|
AppLog.put("Entities.unescape() error\n${it.localizedMessage}", it)
|
||||||
|
}.getOrDefault(s)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun formatKeepImg(html: String?, redirectUrl: URL? = null): String {
|
fun formatKeepImg(html: String?, redirectUrl: URL? = null): String {
|
||||||
|
|||||||
Reference in New Issue
Block a user