pull/354/head
gedoor 4 years ago
parent 6187dd2ac0
commit c448b0dbae
  1. 5
      app/src/main/java/io/legado/app/help/JsExtensions.kt
  2. 3
      app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeByJSoup.kt
  3. 4
      app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt
  4. 3
      app/src/main/java/io/legado/app/model/webBook/BookContent.kt

@ -6,6 +6,7 @@ import io.legado.app.constant.AppConst.dateFormat
import io.legado.app.model.analyzeRule.AnalyzeUrl import io.legado.app.model.analyzeRule.AnalyzeUrl
import io.legado.app.utils.EncoderUtils import io.legado.app.utils.EncoderUtils
import io.legado.app.utils.MD5Utils import io.legado.app.utils.MD5Utils
import io.legado.app.utils.htmlFormat
import org.jetbrains.anko.getStackTraceString import org.jetbrains.anko.getStackTraceString
import java.net.URLEncoder import java.net.URLEncoder
import java.util.* import java.util.*
@ -80,4 +81,8 @@ interface JsExtensions {
"" ""
} }
} }
fun formatHtml(str: String): String {
return str.htmlFormat()
}
} }

@ -3,7 +3,6 @@ package io.legado.app.model.analyzeRule
import android.text.TextUtils.isEmpty import android.text.TextUtils.isEmpty
import android.text.TextUtils.join import android.text.TextUtils.join
import androidx.annotation.Keep import androidx.annotation.Keep
import io.legado.app.utils.htmlFormat
import io.legado.app.utils.splitNotBlank import io.legado.app.utils.splitNotBlank
import org.jsoup.Jsoup import org.jsoup.Jsoup
import org.jsoup.nodes.Element import org.jsoup.nodes.Element
@ -380,7 +379,7 @@ class AnalyzeByJSoup {
"html" -> { "html" -> {
elements.select("script").remove() elements.select("script").remove()
elements.select("style").remove() elements.select("style").remove()
val html = elements.outerHtml().htmlFormat() val html = elements.outerHtml()
textS.add(html) textS.add(html)
} }
"all" -> textS.add(elements.outerHtml()) "all" -> textS.add(elements.outerHtml())

@ -376,7 +376,7 @@ class AnalyzeRule(var book: BaseBook? = null) : JsExtensions {
val jsMatcher = JS_PATTERN.matcher(vRuleStr) val jsMatcher = JS_PATTERN.matcher(vRuleStr)
while (jsMatcher.find()) { while (jsMatcher.find()) {
if (jsMatcher.start() > start) { if (jsMatcher.start() > start) {
tmp = vRuleStr.substring(start, jsMatcher.start()).replace("\n", "") tmp = vRuleStr.substring(start, jsMatcher.start())
.trim { it <= ' ' } .trim { it <= ' ' }
if (!TextUtils.isEmpty(tmp)) { if (!TextUtils.isEmpty(tmp)) {
ruleList.add(SourceRule(tmp, mMode)) ruleList.add(SourceRule(tmp, mMode))
@ -386,7 +386,7 @@ class AnalyzeRule(var book: BaseBook? = null) : JsExtensions {
start = jsMatcher.end() start = jsMatcher.end()
} }
if (vRuleStr.length > start) { if (vRuleStr.length > start) {
tmp = vRuleStr.substring(start).replace("\n", "").trim { it <= ' ' } tmp = vRuleStr.substring(start).trim { it <= ' ' }
if (!TextUtils.isEmpty(tmp)) { if (!TextUtils.isEmpty(tmp)) {
ruleList.add(SourceRule(tmp, mMode)) ruleList.add(SourceRule(tmp, mMode))
} }

@ -10,6 +10,7 @@ import io.legado.app.model.Debug
import io.legado.app.model.analyzeRule.AnalyzeRule import io.legado.app.model.analyzeRule.AnalyzeRule
import io.legado.app.model.analyzeRule.AnalyzeUrl import io.legado.app.model.analyzeRule.AnalyzeUrl
import io.legado.app.utils.NetworkUtils import io.legado.app.utils.NetworkUtils
import io.legado.app.utils.htmlFormat
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
@ -95,7 +96,7 @@ object BookContent {
} }
} }
content.deleteCharAt(content.length - 1) content.deleteCharAt(content.length - 1)
var contentStr = content.toString() var contentStr = content.toString().htmlFormat()
val replaceRegex = bookSource.ruleContent?.replaceRegex?.trim() val replaceRegex = bookSource.ruleContent?.replaceRegex?.trim()
if (!replaceRegex.isNullOrEmpty()) { if (!replaceRegex.isNullOrEmpty()) {
contentStr = AnalyzeRule(book).setContent(contentStr).getString(replaceRegex) contentStr = AnalyzeRule(book).setContent(contentStr).getString(replaceRegex)

Loading…
Cancel
Save