trunk
vilmibm 2022-05-28 01:00:51 +01:00
parent 4fc74f5222
commit 74a9e407dd
1 changed files with 17 additions and 5 deletions

22
main.go
View File

@ -26,19 +26,32 @@ func _main(o opts) error {
} }
output := string(t) 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 { switch o.Mode {
case "html": case "html":
output = strings.ReplaceAll(output, string(ms[0]), output = strings.ReplaceAll(output, rawLink,
fmt.Sprintf("<a href=\"%s\">%s</a>", string(ms[1]), string(ms[2]))) fmt.Sprintf("<a href=\"%s\">%s</a>", link, title))
case "gopher": 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": case "gemini":
break break
} }
} }
if footer != "" {
output = output + "\n\n" + footer
}
fmt.Fprintf(o.Out, output) fmt.Fprintf(o.Out, output)
return nil return nil
@ -51,7 +64,6 @@ type opts struct {
} }
func main() { func main() {
// TODO mode flag
var modeFlag = flag.String("mode", "", "one of html, gopher, gemini.") var modeFlag = flag.String("mode", "", "one of html, gopher, gemini.")
flag.Parse() flag.Parse()
if *modeFlag == "" || (*modeFlag != "html" && *modeFlag != "gopher" && *modeFlag != "gemini") { if *modeFlag == "" || (*modeFlag != "html" && *modeFlag != "gopher" && *modeFlag != "gemini") {