Fixes extra } when rendering hashtags from Markdown

This commit is contained in:
Vitor Pamplona 2024-06-27 19:03:29 -04:00
parent 700974a5ae
commit c18df3a157
3 changed files with 18 additions and 21 deletions

View File

@ -564,7 +564,12 @@ fun HashTag(
Text( Text(
text = annotatedTermsString, text = annotatedTermsString,
modifier = remember { Modifier.clickable { nav("Hashtag/${segment.hashtag}") } }, modifier =
remember {
Modifier.clickable {
nav("Hashtag/${segment.hashtag}")
}
},
inlineContent = inlineContent =
if (hashtagIcon != null) { if (hashtagIcon != null) {
mapOf("inlineContent" to InlineIcon(hashtagIcon)) mapOf("inlineContent" to InlineIcon(hashtagIcon))

View File

@ -66,8 +66,8 @@ class MarkdownMediaRenderer(
override fun shouldRenderLinkPreview( override fun shouldRenderLinkPreview(
title: String?, title: String?,
uri: String, uri: String,
): Boolean { ): Boolean =
return if (canPreview && uri.startsWith("http")) { if (canPreview && uri.startsWith("http")) {
if (title.isNullOrBlank() || title == uri) { if (title.isNullOrBlank() || title == uri) {
true true
} else { } else {
@ -76,7 +76,6 @@ class MarkdownMediaRenderer(
} else { } else {
false false
} }
}
override fun renderImage( override fun renderImage(
title: String?, title: String?,
@ -183,7 +182,7 @@ class MarkdownMediaRenderer(
richTextStringBuilder: RichTextString.Builder, richTextStringBuilder: RichTextString.Builder,
) { ) {
val tagWithoutHash = tag.removePrefix("#") val tagWithoutHash = tag.removePrefix("#")
renderAsCompleteLink(tag, "nostr:Hashtag?id=$tagWithoutHash}", richTextStringBuilder) renderAsCompleteLink(tag, "nostr:Hashtag?id=$tagWithoutHash", richTextStringBuilder)
val hashtagIcon: HashtagIcon? = checkForHashtagWithIcon(tagWithoutHash) val hashtagIcon: HashtagIcon? = checkForHashtagWithIcon(tagWithoutHash)
if (hashtagIcon != null) { if (hashtagIcon != null) {

View File

@ -41,7 +41,7 @@ import java.net.URL
import java.util.regex.Pattern import java.util.regex.Pattern
import kotlin.coroutines.cancellation.CancellationException import kotlin.coroutines.cancellation.CancellationException
class RichTextParser() { class RichTextParser {
fun parseMediaUrl( fun parseMediaUrl(
fullUrl: String, fullUrl: String,
eventTags: ImmutableListOfLists<String>, eventTags: ImmutableListOfLists<String>,
@ -168,15 +168,14 @@ class RichTextParser() {
private fun isNumber(word: String) = numberPattern.matcher(word).matches() private fun isNumber(word: String) = numberPattern.matcher(word).matches()
private fun isPhoneNumberChar(c: Char): Boolean { private fun isPhoneNumberChar(c: Char): Boolean =
return when (c) { when (c) {
in '0'..'9' -> true in '0'..'9' -> true
'-' -> true '-' -> true
' ' -> true ' ' -> true
'.' -> true '.' -> true
else -> false else -> false
} }
}
fun isPotentialPhoneNumber(word: String): Boolean { fun isPotentialPhoneNumber(word: String): Boolean {
if (word.length !in 7..14) return false if (word.length !in 7..14) return false
@ -191,13 +190,9 @@ class RichTextParser() {
return isPotentialNumber return isPotentialNumber
} }
fun isDate(word: String): Boolean { fun isDate(word: String): Boolean = shortDatePattern.matcher(word).matches() || longDatePattern.matcher(word).matches()
return shortDatePattern.matcher(word).matches() || longDatePattern.matcher(word).matches()
}
private fun isArabic(text: String): Boolean { private fun isArabic(text: String): Boolean = text.any { it in '\u0600'..'\u06FF' || it in '\u0750'..'\u077F' }
return text.any { it in '\u0600'..'\u06FF' || it in '\u0750'..'\u077F' }
}
private fun wordIdentifier( private fun wordIdentifier(
word: String, word: String,
@ -331,15 +326,14 @@ class RichTextParser() {
it.uppercase() it.uppercase()
} }
private fun removeQueryParamsForExtensionComparison(fullUrl: String): String { private fun removeQueryParamsForExtensionComparison(fullUrl: String): String =
return if (fullUrl.contains("?")) { if (fullUrl.contains("?")) {
fullUrl.split("?")[0].lowercase() fullUrl.split("?")[0].lowercase()
} else if (fullUrl.contains("#")) { } else if (fullUrl.contains("#")) {
fullUrl.split("#")[0].lowercase() fullUrl.split("#")[0].lowercase()
} else { } else {
fullUrl.lowercase() fullUrl.lowercase()
} }
}
fun isImageOrVideoUrl(url: String): Boolean { fun isImageOrVideoUrl(url: String): Boolean {
val removedParamsFromUrl = removeQueryParamsForExtensionComparison(url) val removedParamsFromUrl = removeQueryParamsForExtensionComparison(url)
@ -358,8 +352,8 @@ class RichTextParser() {
return videoExtensions.any { removedParamsFromUrl.endsWith(it) } return videoExtensions.any { removedParamsFromUrl.endsWith(it) }
} }
fun isValidURL(url: String?): Boolean { fun isValidURL(url: String?): Boolean =
return try { try {
URL(url).toURI() URL(url).toURI()
true true
} catch (e: MalformedURLException) { } catch (e: MalformedURLException) {
@ -367,7 +361,6 @@ class RichTextParser() {
} catch (e: URISyntaxException) { } catch (e: URISyntaxException) {
false false
} }
}
fun parseImageOrVideo(fullUrl: String): BaseMediaContent { fun parseImageOrVideo(fullUrl: String): BaseMediaContent {
val removedParamsFromUrl = removeQueryParamsForExtensionComparison(fullUrl) val removedParamsFromUrl = removeQueryParamsForExtensionComparison(fullUrl)