From 74a9e407ddfddae2deeaa0347409310506e561fe Mon Sep 17 00:00:00 2001 From: vilmibm Date: Sat, 28 May 2022 01:00:51 +0100 Subject: [PATCH] gopher --- main.go | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/main.go b/main.go index 8bb7532..b669352 100644 --- a/main.go +++ b/main.go @@ -26,19 +26,32 @@ func _main(o opts) error { } output := string(t) + footer := "" - for _, ms := range mms { + for ix, ms := range mms { + rawLink := string(ms[0]) + link := string(ms[1]) + title := string(ms[2]) switch o.Mode { case "html": - output = strings.ReplaceAll(output, string(ms[0]), - fmt.Sprintf("%s", string(ms[1]), string(ms[2]))) + output = strings.ReplaceAll(output, rawLink, + fmt.Sprintf("%s", link, title)) case "gopher": - break + output = strings.ReplaceAll(output, rawLink, fmt.Sprintf("%s[%d]", title, ix)) + linkType := "i" + if strings.HasPrefix(link, "http") { + linkType = "h" + } + footer += fmt.Sprintf("%s[%d]: %s %s\n", linkType, ix, title, link) case "gemini": break } } + if footer != "" { + output = output + "\n\n" + footer + } + fmt.Fprintf(o.Out, output) return nil @@ -51,7 +64,6 @@ type opts struct { } func main() { - // TODO mode flag var modeFlag = flag.String("mode", "", "one of html, gopher, gemini.") flag.Parse() if *modeFlag == "" || (*modeFlag != "html" && *modeFlag != "gopher" && *modeFlag != "gemini") {