Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions announcements/announcements.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package announcements
import (
"context"
"fmt"
"regexp"
"strings"
"time"

Expand Down Expand Up @@ -111,10 +112,21 @@ func remove(im *imap.Dialer, uids []int) error {
return err
}

var bracketLinkRe = regexp.MustCompile(`\[((https?://)([^\]]*[^\\\]]))\]\((https?://[^)]*[^\\)])\)`)

var converter = md.NewConverter("", true, &md.Options{
HeadingStyle: "setext",
StrongDelimiter: "**",
LinkStyle: "inlined",
}).After(func(content string) string {
return bracketLinkRe.ReplaceAllStringFunc(content, func(bracketLink string) string {
matches := bracketLinkRe.FindStringSubmatch(bracketLink)
text, textNoSchema, link := matches[1], matches[3], matches[4]
if text == link {
return "<" + link + ">"
}
return fmt.Sprintf("[%s](%s)", textNoSchema, link)
})
})

// markdownBody takes a html string and converts it into a formatted markdown body.
Expand Down