diff --git a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt
index fd814d00d..225be549c 100644
--- a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt
+++ b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt
@@ -597,13 +597,9 @@ class AnalyzeRule(val ruleData: RuleDataInterface) : JsExtensions {
private fun isRule(ruleStr: String): Boolean {
return ruleStr.startsWith('@') //js首个字符不可能是@,除非是装饰器,所以@开头规定为规则
- || ruleStr.startsWith('$') //js首个字符不可能是$,因为并未注入$变量,且$1之类的东西已被替换,不会影响此处判断
+ || ruleStr.startsWith("$.")
+ || ruleStr.startsWith("$[")
|| ruleStr.startsWith("//")
- || ruleStr.startsWith("class")//js首个字符串不可能是class,因为并未注入相关字符串开头的变量
- || ruleStr.startsWith("id")//js首个字符串不可能是id,因为并未注入相关字符串开头的变量
- || ruleStr.startsWith("tag")//js首个字符串不可能是tag,因为并未注入相关字符串开头的变量
- || ruleStr.startsWith("text")//js首个字符串不可能是text,因为并未注入相关字符串开头的变量
- || ruleStr.startsWith("children")//js首个字符串不可能是children,因为并未注入相关字符串开头的变量
}
}
diff --git a/app/src/main/java/io/legado/app/service/help/ReadBook.kt b/app/src/main/java/io/legado/app/service/help/ReadBook.kt
index 62ab815c0..f2b765b9b 100644
--- a/app/src/main/java/io/legado/app/service/help/ReadBook.kt
+++ b/app/src/main/java/io/legado/app/service/help/ReadBook.kt
@@ -493,4 +493,4 @@ object ReadBook {
fun upPageAnim()
}
-}
\ No newline at end of file
+}
diff --git a/app/src/main/java/io/legado/app/utils/HtmlFormatter.kt b/app/src/main/java/io/legado/app/utils/HtmlFormatter.kt
index 5f69f5b9f..4dfb2c35f 100644
--- a/app/src/main/java/io/legado/app/utils/HtmlFormatter.kt
+++ b/app/src/main/java/io/legado/app/utils/HtmlFormatter.kt
@@ -11,10 +11,10 @@ object HtmlFormatter {
fun format(html: String?, otherRegex: Regex = otherHtmlRegex): String {
html ?: return ""
return html.replace(wrapHtmlRegex, "\n")
- .replace(otherRegex, "")
- .replace("\\s*\\n+\\s*".toRegex(), "\n ")
- .replace("^[\\n\\s]+".toRegex(), " ")
- .replace("[\\n\\s]+$".toRegex(), "")
+ .replace(otherRegex, "")
+ .replace("\\s*\\n+\\s*".toRegex(), "\n ")
+ .replace("^[\\n\\s]+".toRegex(), " ")
+ .replace("[\\n\\s]+$".toRegex(), "")
}
fun formatKeepImg(html: String?) = format(html, notImgHtmlRegex)
@@ -22,65 +22,47 @@ object HtmlFormatter {
fun formatKeepImg(html: String?, redirectUrl: URL?): String {
html ?: return ""
val keepImgHtml = html.replace(wrapHtmlRegex, "\n")
- .replace(notImgHtmlRegex, "")
- .replace("[\\n\\s]+\$|^[\\n\\s]*".toRegex(), "")
- .replace("\\s*\\n+\\s*".toRegex(), "\n")
+ .replace(notImgHtmlRegex, "")
+ .replace("[\\n\\s]+\$|^[\\n\\s]*".toRegex(), "")
+ .replace("\\s*\\n+\\s*".toRegex(), "\n")
val sb = StringBuffer()
val hasDataType:Boolean //是否有数据属性
//图片有data-开头的数据属性时优先用数据属性作为src,没有数据属性时匹配src
val imgPattern = Pattern.compile(
- if(keepImgHtml.matches("]*data-".toRegex())) {
- hasDataType = true
- "]*data-[^=]*= *\"([^\"])\"[^>]*>"
- }
- else {
- hasDataType = false
- "]*src *= *\"([^\"{]+(?:\\{(?:[^{}]|\\{[^{}]*\\})*\\})?)\"[^>]*>"
- }, Pattern.CASE_INSENSITIVE
+ if(keepImgHtml.matches("]*data-".toRegex())) {
+ hasDataType = true
+ "]*data-[^=]*= *\"([^\"])\"[^>]*>"
+ }
+ else {
+ hasDataType = false
+ "]*src *= *\"([^\"{]+(?:\\{(?:[^{}]|\\{[^{}]*\\})*\\})?)\"[^>]*>"
+ }, Pattern.CASE_INSENSITIVE
)
val matcher = imgPattern.matcher(keepImgHtml)
var appendPos = 0
- if(matcher.find()){
- if(hasDataType || matcher.group(1)!!.indexOf(',') == -1) { //图片无参
-
- do{
- sb.append(keepImgHtml.substring(appendPos, matcher.start()).replace("\n","\n ")) //非图片部分换行缩进
- sb.append( "" )
- appendPos = matcher.end()
- }while (matcher.find())
-
- }else{ //图片有参
-
- do{
- val url = matcher.group(1)!!
- val urlBefore = url.substringBefore(',')
- val beforeStr = keepImgHtml.substring(appendPos, matcher.start())
- sb.append( if(beforeStr == "\n") '\n' else beforeStr.replace("\n","\n ") ) //缩进换行下个非图片段落
- sb.append(
- ""
- )
- appendPos = matcher.end()
- }while(matcher.find())
-
- }
+ )
+ }${
+ url.substring(urlBefore.length)
+ }\">"
+ )
+ appendPos = matcher.end()
}
if (appendPos < keepImgHtml.length) {
- val beforeStr = keepImgHtml.substring(appendPos, keepImgHtml.length)
- sb.append( if(beforeStr == "\n") '\n' else beforeStr.replace("\n","\n ") ) //缩进换行下个非图片段落
+ sb.append( keepImgHtml.substring( appendPos, keepImgHtml.length ).replace("\n","\n ") ) //缩进换行下个非图片段落
}
return sb.toString()
}