Skip to content

Commit

Permalink
Check that a string contains markdown symbols instead of matches (#2080)
Browse files Browse the repository at this point in the history
.* 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
  • Loading branch information
EanLombardo authored Sep 5, 2024
1 parent 5a27d7c commit 1385062
Showing 1 changed file with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit 1385062

Please sign in to comment.