diff --git a/email.go b/email.go index b7a4e15..52c10bd 100644 --- a/email.go +++ b/email.go @@ -9,6 +9,8 @@ import ( tea "github.com/charmbracelet/bubbletea" "github.com/resendlabs/resend-go" "github.com/yuin/goldmark" + "github.com/yuin/goldmark/extension" + renderer "github.com/yuin/goldmark/renderer/html" ) const TO_SEPARATOR = "," @@ -41,7 +43,21 @@ func sendEmail(to []string, from, subject, body string, paths []string) error { html := bytes.NewBufferString("") // If the conversion fails, we'll simply send the plain-text body. - _ = goldmark.Convert([]byte(body), html) + if unsafe { + markdown := goldmark.New( + goldmark.WithRendererOptions( + renderer.WithUnsafe(), + ), + goldmark.WithExtensions( + extension.Strikethrough, + extension.Table, + extension.Linkify, + ), + ) + _ = markdown.Convert([]byte(body), html) + } else { + _ = goldmark.Convert([]byte(body), html) + } request := &resend.SendEmailRequest{ From: from, diff --git a/main.go b/main.go index 0c64fdb..afdbc88 100644 --- a/main.go +++ b/main.go @@ -15,6 +15,7 @@ import ( ) const RESEND_API_KEY = "RESEND_API_KEY" +const UNSAFE_HTML = "POP_UNSAFE_HTML" const POP_FROM = "POP_FROM" const POP_SIGNATURE = "POP_SIGNATURE" @@ -25,6 +26,7 @@ var ( body string attachments []string preview bool + unsafe bool signature string ) @@ -151,6 +153,8 @@ func init() { rootCmd.Flags().StringVarP(&from, "from", "f", envFrom, "Email's sender "+commentStyle.Render("($"+POP_FROM+")")) rootCmd.Flags().StringVarP(&subject, "subject", "s", "", "Email's subject") rootCmd.Flags().BoolVarP(&preview, "preview", "p", false, "Whether to preview the email before sending") + envUnsafe := os.Getenv(UNSAFE_HTML) == "true" + rootCmd.Flags().BoolVarP(&unsafe, "unsafe", "u", envUnsafe, "Whether to allow unsafe HTML in the email body, also enable some extra markdown features (Experimental)") envSignature := os.Getenv("POP_SIGNATURE") rootCmd.Flags().StringVarP(&signature, "signature", "x", envSignature, "Signature to display at the end of the email. "+commentStyle.Render("($"+POP_SIGNATURE+")"))