diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/notification.go | 4 | ||||
-rw-r--r-- | app/notification_test.go | 6 |
2 files changed, 8 insertions, 2 deletions
diff --git a/app/notification.go b/app/notification.go index b0a5d83ad..c86e1669f 100644 --- a/app/notification.go +++ b/app/notification.go @@ -839,14 +839,14 @@ func GetExplicitMentions(message string, keywords map[string][]string) (map[stri // Matches a line containing only ``` and a potential language definition, any number of lines not containing ```, // and then either a line containing only ``` or the end of the text -var codeBlockPattern = regexp.MustCompile("(?m)^[^\\S\n]*\\`\\`\\`.*$[\\s\\S]+?(^[^\\S\n]*\\`\\`\\`$|\\z)") +var codeBlockPattern = regexp.MustCompile("(?m)^[^\\S\n]*[\\`~]{3}.*$[\\s\\S]+?(^[^\\S\n]*[`~]{3}$|\\z)") // Matches a backquote, either some text or any number of non-empty lines, and then a final backquote var inlineCodePattern = regexp.MustCompile("(?m)\\`+(?:.+?|.*?\n(.*?\\S.*?\n)*.*?)\\`+") // Strips pre-formatted text and code blocks from a Markdown string by replacing them with whitespace func removeCodeFromMessage(message string) string { - if strings.Contains(message, "```") { + if strings.Contains(message, "```") || strings.Contains(message, "~~~") { message = codeBlockPattern.ReplaceAllString(message, "") } diff --git a/app/notification_test.go b/app/notification_test.go index 02b6e1db0..e0c1a54e6 100644 --- a/app/notification_test.go +++ b/app/notification_test.go @@ -399,6 +399,12 @@ func TestRemoveCodeFromMessage(t *testing.T) { if actual := removeCodeFromMessage(input); actual != expected { t.Fatalf("received incorrect output\n\nGot:\n%v\n\nExpected:\n%v\n", actual, expected) } + + input = "this is text with\n~~~\na code block\n~~~\nin it" + expected = "this is text with\n\nin it" + if actual := removeCodeFromMessage(input); actual != expected { + t.Fatalf("received incorrect output\n\nGot:\n%v\n\nExpected:\n%v\n", actual, expected) + } } func TestGetMentionKeywords(t *testing.T) { |