Check that a string contains markdown symbols instead of matches (#2080)

.* does not match line breaks, so this regex would never apply to multiline text. This checks for contains instead of using .* to account for this.

Fixes #2049
This commit is contained in:
Ean Lombardo 2024-09-05 08:19:08 -07:00 committed by GitHub
parent 5a27d7cd98
commit 138506211a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -204,12 +204,12 @@ object MarkdownParser {
return EmojiParser.convertToCheatCode(input.toString())
}
private val markdownRegex = ".*[*#_\\[`~].*".toRegex()
private val markdownRegex = "[*#_\\[`~]".toRegex()
private val imageMarkdownRegex = """!\[.*?]\(.*?".*?"\)""".toRegex()
private val markdownLinkRegex = "\\[([^\\]]+)\\]\\(([^\\)]+)\\)".toRegex()
fun containsMarkdown(text: String): Boolean {
return text.matches(markdownRegex) ||
return text.contains(markdownRegex) ||
text.contains(imageMarkdownRegex) ||
text.contains(markdownLinkRegex)
}