replacing links with their content, in the future this should be a representation with ranges of the formatting within the text

This commit is contained in:
Adam Brown 2022-05-09 18:20:42 +01:00
parent 299c6af27a
commit 8716500d99
1 changed files with 10 additions and 0 deletions

View File

@ -63,9 +63,19 @@ fun String.stripTags() = this
} ?: this
}
.trim()
.replaceLinks()
.replace("<em>", "")
.replace("</em>", "")
.replace("&quot;", "\"")
.replace("&#39;", "'")
private fun String.replaceLinks(): String {
return this.indexOfOrNull("<a href=")?.let { start ->
val openTagClose = indexOfOrNull("\">")!!
val end = indexOfOrNull("</a>")!!
val content = this.substring(openTagClose + "\">".length, end)
this.replaceRange(start, end + "</a>".length, content)
} ?: this
}
private fun ApiTimelineEvent.TimelineMessage.asTextContent() = this.content as ApiTimelineEvent.TimelineMessage.Content.Text