fusch.online

git / lists / casts

git.fusch.online/minbox

Maildir to static html converter
git clone git://git.fusch.online/minbox
Log / Files / Readme / License / Issues

commit 7c39caf2bdecf070258f05b1d99eaa2e53d45558
parent 59e28084808348628876c8babbf0ebfe92f7ccb0
Author: tutti <tutti@fusch.online>
Date:   Mon,  8 Jul 2019 12:41:20 +0200

naiv autolinking

Diffstat:
Mminbox.go | 15+++++++++++++++
1 file changed, 15 insertions(+), 0 deletions(-)

diff --git a/minbox.go b/minbox.go @@ -9,6 +9,7 @@ import ( "net/mail" "os" "path/filepath" + "regexp" "strings" textTemplate "text/template" "time" @@ -237,6 +238,20 @@ func main() { "name": func(s string) string { return strings.Split(s, "@")[0] }, + "autolink": func(s string) htmlTemplate.HTML { + re := regexp.MustCompile(`(http[s]?:\/\/)?[\w\d-_.]+[\w\d][@\.][\w\d-&?=]+([\./#][\w\d-&?=]+)*[/]?`) + rm := regexp.MustCompile(`[\w\d\-_.]+[\w\d]@[\w\d-]+([\./][\w\d-]+)+`) + + html := re.ReplaceAllStringFunc(s, func(old string) string { + if rm.MatchString(old) { + return "<a href=\"mailto:" + old + "\">" + old + "</a>" + } else { + return "<a href=\"" + old + "\">" + old + "</a>" + } + }) + + return htmlTemplate.HTML(html) + }, "double": func(level int) int { return level * 2 },