This commit is contained in:
Horis 2024-01-18 16:32:37 +08:00
parent 6979054a57
commit 88476f7a82
4 changed files with 28 additions and 9 deletions

View File

@ -45,9 +45,20 @@ class AnalyzeByJSoup(doc: Any) {
/** /**
* 合并内容列表,得到内容 * 合并内容列表,得到内容
*/ */
internal fun getString(ruleStr: String) = internal fun getString(ruleStr: String): String? {
if (ruleStr.isEmpty()) null if (ruleStr.isEmpty()) {
else getStringList(ruleStr).takeIf { it.isNotEmpty() }?.joinToString("\n") return null
}
val list = getStringList(ruleStr)
if (list.isEmpty()) {
return null
}
if (list.size == 1){
return list.first()
}
return list.joinToString("\n")
}
/** /**
* 获取一个字符串 * 获取一个字符串

View File

@ -295,9 +295,12 @@ class AnalyzeRule(
} }
} }
if (result == null) result = "" if (result == null) result = ""
val str = if (unescape) { val resultStr = result.toString()
StringEscapeUtils.unescapeHtml4(result.toString()) val str = if (unescape && resultStr.indexOf('&') > -1) {
} else result.toString() StringEscapeUtils.unescapeHtml4(resultStr)
} else {
resultStr
}
if (isUrl) { if (isUrl) {
return if (str.isBlank()) { return if (str.isBlank()) {
baseUrl ?: "" baseUrl ?: ""

View File

@ -137,8 +137,11 @@ object LocalBook {
"获取本地书籍内容失败\n${e.localizedMessage}" "获取本地书籍内容失败\n${e.localizedMessage}"
} }
if (book.isEpub) { if (book.isEpub) {
content = content?.replace("<img", "< img", true) ?: return null content ?: return null
return StringEscapeUtils.unescapeHtml4(content) if (content.indexOf('&') > -1) {
content = content.replace("<img", "< img", true)
return StringEscapeUtils.unescapeHtml4(content)
}
} }
return content return content
} }

View File

@ -169,7 +169,9 @@ object BookContent {
//获取正文 //获取正文
var content = analyzeRule.getString(contentRule.content, unescape = false) var content = analyzeRule.getString(contentRule.content, unescape = false)
content = HtmlFormatter.formatKeepImg(content, rUrl) content = HtmlFormatter.formatKeepImg(content, rUrl)
content = StringEscapeUtils.unescapeHtml4(content) if (content.indexOf('&') > -1) {
content = StringEscapeUtils.unescapeHtml4(content)
}
//获取下一页链接 //获取下一页链接
if (getNextPageUrl) { if (getNextPageUrl) {
val nextUrlRule = contentRule.nextContentUrl val nextUrlRule = contentRule.nextContentUrl