diff --git a/app/src/main/java/io/legado/app/model/localBook/EPUBFile.kt b/app/src/main/java/io/legado/app/model/localBook/EPUBFile.kt index 68ffd484f..85bb5794b 100644 --- a/app/src/main/java/io/legado/app/model/localBook/EPUBFile.kt +++ b/app/src/main/java/io/legado/app/model/localBook/EPUBFile.kt @@ -6,10 +6,7 @@ import android.net.Uri import android.text.TextUtils import io.legado.app.App import io.legado.app.data.entities.BookChapter -import io.legado.app.utils.FileUtils -import io.legado.app.utils.MD5Utils -import io.legado.app.utils.externalFilesDir -import io.legado.app.utils.isContentPath +import io.legado.app.utils.* import nl.siegmann.epublib.domain.Book import nl.siegmann.epublib.domain.TOCReference import nl.siegmann.epublib.epub.EpubReader @@ -95,11 +92,7 @@ class EPUBFile(val book: io.legado.app.data.entities.Book) { val elements = doc.body().children() elements.select("script").remove() elements.select("style").remove() - return elements.outerHtml() - .replace("]*>".toRegex(), "\n") - .replace("\\s*\\n+\\s*".toRegex(), "\n  ") - .replace("^[\\n\\s]+".toRegex(), "  ") - .replace("[\\n\\s]+$".toRegex(), "") + return elements.outerHtml().htmlFormat() } return null } diff --git a/app/src/main/java/io/legado/app/utils/StringExtensions.kt b/app/src/main/java/io/legado/app/utils/StringExtensions.kt index b3d599860..ef5ebe933 100644 --- a/app/src/main/java/io/legado/app/utils/StringExtensions.kt +++ b/app/src/main/java/io/legado/app/utils/StringExtensions.kt @@ -33,7 +33,7 @@ fun String?.isJsonArray(): Boolean = } ?: false fun String?.htmlFormat(): String = - this?.replace("]*>".toRegex(), "\n") + this?.replace("]*>".toRegex(), "\n") ?.replace("<[script>]*.*?>| ".toRegex(), "") ?.replace("\\s*\\n+\\s*".toRegex(), "\n  ") ?.replace("^[\\n\\s]+".toRegex(), "  ")