diff --git a/app/notification_email.go b/app/notification_email.go index b5ebf1f352..b32d0f669f 100644 --- a/app/notification_email.go +++ b/app/notification_email.go @@ -15,6 +15,7 @@ import ( "github.com/mattermost/mattermost-server/v6/model" "github.com/mattermost/mattermost-server/v6/shared/i18n" "github.com/mattermost/mattermost-server/v6/shared/mlog" + "github.com/mattermost/mattermost-server/v6/utils" "github.com/pkg/errors" ) @@ -213,10 +214,16 @@ func (a *App) getNotificationEmailBody(recipient *model.User, post *model.Post, if emailNotificationContentsType == model.EmailNotificationContentsFull { postMessage := a.GetMessageForNotification(post, translateFunc) postMessage = html.EscapeString(postMessage) - normalizedPostMessage, err := a.generateHyperlinkForChannels(postMessage, teamName, landingURL) + mdPostMessage, mdErr := utils.MarkdownToHTML(postMessage) + if mdErr != nil { + mlog.Warn("Encountered error while converting markdown to HTML", mlog.Err(mdErr)) + mdPostMessage = postMessage + } + + normalizedPostMessage, err := a.generateHyperlinkForChannels(mdPostMessage, teamName, landingURL) if err != nil { mlog.Warn("Encountered error while generating hyperlink for channels", mlog.String("team_name", teamName), mlog.Err(err)) - normalizedPostMessage = postMessage + normalizedPostMessage = mdPostMessage } pData.Message = template.HTML(normalizedPostMessage) pData.Time = translateFunc("app.notification.body.dm.time", messageTime) diff --git a/app/notification_email_test.go b/app/notification_email_test.go index 6f08db581a..41b58e71d4 100644 --- a/app/notification_email_test.go +++ b/app/notification_email_test.go @@ -825,3 +825,112 @@ func TestLandingLinkPermalink(t *testing.T) { require.NoError(t, err) require.Contains(t, body, teamURL+"/pl/"+post.Id, fmt.Sprintf("Expected email text '%s'. Got %s", teamURL, body)) } + +func TestMarkdownConversion(t *testing.T) { + tests := []struct { + name string + args string + want string + }{ + { + name: "markdown: escape string test", + args: "not bold", + want: "<b>not bold</b>", + }, + { + name: "markdown: strong", + args: "This is **Mattermost**", + want: "This is Mattermost", + }, + { + name: "markdown: blockquote", + args: "Below is blockquote\n" + + "> This is Mattermost blockquote\n" + + "> on multiple lines!", + want: "
\n" + + "", + }, + { + name: "markdown: emphasis", + args: "This is *Mattermost*", + want: "This is Mattermost", + }, + { + name: "markdown: links", + args: "This is [Mattermost](https://mattermost.com)", + want: "This is Mattermost", + }, + { + name: "markdown: strikethrough", + args: "This is ~~Mattermost~~", + want: "This isThis is Mattermost blockquote\n" + + "on multiple lines!
\n" + + "
| Tables | \n" + + "Are | \n" + + "Cool | \n" + + "
|---|---|---|
| col 3 is | \n" + + "right-aligned | \n" + + "$1600 | \n" + + "
| col 2 is | \n" + + "centered | \n" + + "$12 | \n" + + "
| zebra stripes | \n" + + "are neat | \n" + + "$1 | \n" + + "