MangaDex: Clean manga descriptions (#10674)

* 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
This commit is contained in:
nicki 2022-02-04 15:56:31 +05:30 committed by GitHub
parent 6d89ecf346
commit 81e98ae6ae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -61,21 +61,16 @@ class MangaDexHelper() {
fun getLatestChapterOffset(page: Int): String = (MDConstants.latestChapterLimit * (page - 1)).toString() 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 * chapter name to actual characters for example ♥ will show
*/ */
fun cleanString(string: String): String { fun cleanString(string: String): String {
val bbRegex = val unescapedString = Parser.unescapeEntities(string, false)
"""\[(\w+)[^]]*](.*?)\[/\1]""".toRegex()
var intermediate = string return unescapedString
.replace("[list]", "") .substringBefore("---")
.replace("[/list]", "") .replace(markdownLinksRegex, "$1")
.replace("[*]", "") .trim()
// Recursively remove nested bbcode
while (bbRegex.containsMatchIn(intermediate)) {
intermediate = intermediate.replace(bbRegex, "$2")
}
return Parser.unescapeEntities(intermediate, false)
} }
/** /**
@ -112,6 +107,8 @@ class MangaDexHelper() {
val USE_CACHE = CacheControl.Builder() val USE_CACHE = CacheControl.Builder()
.maxStale(Integer.MAX_VALUE, TimeUnit.SECONDS) .maxStale(Integer.MAX_VALUE, TimeUnit.SECONDS)
.build() .build()
val markdownLinksRegex = "\\[([^]]+)\\]\\(([^)]+)\\)".toRegex()
} }
// Check the token map to see if the md@home host is still valid // Check the token map to see if the md@home host is still valid