Don't think of mangadex chapter names as markdown (#18434)

* fix an edge case on chapter name cleaner

maybe closes https://github.com/tachiyomiorg/tachiyomi-extensions/issues/18407

* forgot about alt titles

* update javadoc to match the function usage
This commit is contained in:
nicki 2023-10-08 16:47:05 -05:00 committed by GitHub
parent 1d28b6dc89
commit 1c8478fcca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 8 deletions

View File

@ -6,7 +6,7 @@ ext {
extName = 'MangaDex'
pkgNameSuffix = 'all.mangadex'
extClass = '.MangaDexFactory'
extVersionCode = 188
extVersionCode = 189
isNsfw = true
}

View File

@ -143,12 +143,19 @@ class MangaDexHelper(lang: String) {
(MDConstants.latestChapterLimit * (page - 1)).toString()
/**
* Remove any HTML characters in description or chapter name to actual
* characters. For example ♥ will show . It also removes
* Markdown syntax for links, italic and bold.
* Remove any HTML characters in manga or chapter name to actual
* characters. For example ♥ will show .
*/
private fun String.removeEntities(): String {
return Parser.unescapeEntities(this, false)
}
/**
* Remove any HTML characters in description to actual characters.
* It also removes Markdown syntax for links, italic and bold.
*/
private fun String.removeEntitiesAndMarkdown(): String {
return Parser.unescapeEntities(this, false)
return removeEntities()
.substringBefore("---")
.replace(markdownLinksRegex, "$1")
.replace(markdownItalicBoldRegex, "$1")
@ -284,7 +291,7 @@ class MangaDexHelper(lang: String) {
?: mangaDataDto.attributes.altTitles
.find { (it[lang] ?: it["en"]) !== null }
?.values?.singleOrNull() // find something else from alt titles
title = dirtyTitle?.removeEntitiesAndMarkdown().orEmpty()
title = dirtyTitle?.removeEntities().orEmpty()
coverFileName?.let {
thumbnail_url = when (!coverSuffix.isNullOrEmpty()) {
@ -359,7 +366,7 @@ class MangaDexHelper(lang: String) {
if (altTitles.isNotEmpty()) {
val altTitlesDesc = altTitles
.joinToString("\n", "${intl["alternative_titles"]}\n") { "$it" }
desc += (if (desc.isBlank()) "" else "\n\n") + altTitlesDesc.removeEntitiesAndMarkdown()
desc += (if (desc.isBlank()) "" else "\n\n") + altTitlesDesc.removeEntities()
}
}
@ -427,7 +434,7 @@ class MangaDexHelper(lang: String) {
return SChapter.create().apply {
url = "/chapter/${chapterDataDto.id}"
name = chapterName.joinToString(" ").removeEntitiesAndMarkdown()
name = chapterName.joinToString(" ").removeEntities()
date_upload = parseDate(attr.publishAt)
scanlator = groups
}