From 81e98ae6ae98532147e8c09310d7eb1ce9f3a8ef Mon Sep 17 00:00:00 2001 From: nicki <72807749+curche@users.noreply.github.com> Date: Fri, 4 Feb 2022 15:56:31 +0530 Subject: [PATCH] MangaDex: Clean manga descriptions (#10674) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * MangaDex: Clean manga descriptions Closes #10610 * Incrememnt mangadex.extVersionCode * Remove bbcode cleanup utility Since bbcode has been replaced with markdown. So, this is no longer required * Don't forgot to unescape html characters bbcode might be gone but &hearts still need to be converted to ♥ * Update `cleanString` method description * Remove trailing newlines Using Trim takes cares of whitespace too * Move regex to companion object so that they dont get instantiated everytime * Revert "Incrememnt mangadex.extVersionCode" This reverts commit 73c89933cc36cb41fd6691641c75acf0b6f49c45. Will be added back in a separate minor PR --- .../extension/all/mangadex/MangaDexHelper.kt | 21 ++++++++----------- 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/src/all/mangadex/src/eu/kanade/tachiyomi/extension/all/mangadex/MangaDexHelper.kt b/src/all/mangadex/src/eu/kanade/tachiyomi/extension/all/mangadex/MangaDexHelper.kt index a85afa7d6..68a6edfe5 100644 --- a/src/all/mangadex/src/eu/kanade/tachiyomi/extension/all/mangadex/MangaDexHelper.kt +++ b/src/all/mangadex/src/eu/kanade/tachiyomi/extension/all/mangadex/MangaDexHelper.kt @@ -61,21 +61,16 @@ class MangaDexHelper() { fun getLatestChapterOffset(page: Int): String = (MDConstants.latestChapterLimit * (page - 1)).toString() /** - * Remove bbcode tags as well as parses any html characters in description or + * Remove markdown links as well as parse any html characters in description or * chapter name to actual characters for example ♥ will show ♥ */ fun cleanString(string: String): String { - val bbRegex = - """\[(\w+)[^]]*](.*?)\[/\1]""".toRegex() - var intermediate = string - .replace("[list]", "") - .replace("[/list]", "") - .replace("[*]", "") - // Recursively remove nested bbcode - while (bbRegex.containsMatchIn(intermediate)) { - intermediate = intermediate.replace(bbRegex, "$2") - } - return Parser.unescapeEntities(intermediate, false) + val unescapedString = Parser.unescapeEntities(string, false) + + return unescapedString + .substringBefore("---") + .replace(markdownLinksRegex, "$1") + .trim() } /** @@ -112,6 +107,8 @@ class MangaDexHelper() { val USE_CACHE = CacheControl.Builder() .maxStale(Integer.MAX_VALUE, TimeUnit.SECONDS) .build() + + val markdownLinksRegex = "\\[([^]]+)\\]\\(([^)]+)\\)".toRegex() } // Check the token map to see if the md@home host is still valid