Horis hace 3 años
padre
commit
739c1292c0

+ 17 - 8
app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt

@@ -201,11 +201,18 @@ class AnalyzeRule(
         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
     fun getString(
         ruleList: List<SourceRule>,
         mContent: Any? = null,
-        isUrl: Boolean = false
+        isUrl: Boolean = false,
+        unescape: Boolean = true
     ): String {
         var result: Any? = null
         val content = mContent ?: this.content
@@ -239,13 +246,15 @@ class AnalyzeRule(
             }
         }
         if (result == null) result = ""
-        val str = kotlin.runCatching {
-            Entities.unescape(result.toString())
-        }.onFailure {
-            log("Entities.unescape() error\n${it.localizedMessage}")
-        }.getOrElse {
-            result.toString()
-        }
+        val str = if (unescape) {
+            kotlin.runCatching {
+                Entities.unescape(result.toString())
+            }.onFailure {
+                log("Entities.unescape() error\n${it.localizedMessage}")
+            }.getOrElse {
+                result.toString()
+            }
+        } else result.toString()
         if (isUrl) {
             return if (str.isBlank()) {
                 baseUrl ?: ""

+ 1 - 1
app/src/main/java/io/legado/app/model/webBook/BookContent.kt

@@ -150,7 +150,7 @@ object BookContent {
         val nextUrlList = arrayListOf<String>()
         analyzeRule.chapter = chapter
         //获取正文
-        var content = analyzeRule.getString(contentRule.content)
+        var content = analyzeRule.getString(contentRule.content, unescape = false)
         content = HtmlFormatter.formatKeepImg(content, rUrl)
         //获取下一页链接
         val nextUrlRule = contentRule.nextContentUrl

+ 9 - 0
app/src/main/java/io/legado/app/utils/HtmlFormatter.kt

@@ -1,6 +1,8 @@
 package io.legado.app.utils
 
+import io.legado.app.constant.AppLog
 import io.legado.app.model.analyzeRule.AnalyzeUrl
+import org.jsoup.nodes.Entities
 import java.net.URL
 import java.util.regex.Pattern
 
@@ -29,6 +31,13 @@ object HtmlFormatter {
             .replace("\\s*\\n+\\s*".toRegex(), "\n  ")
             .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 {