gopher
This commit is contained in:
		
							parent
							
								
									4fc74f5222
								
							
						
					
					
						commit
						74a9e407dd
					
				
							
								
								
									
										22
									
								
								main.go
									
									
									
									
									
								
							
							
						
						
									
										22
									
								
								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("<a href=\"%s\">%s</a>", string(ms[1]), string(ms[2])))
 | 
			
		||||
			output = strings.ReplaceAll(output, rawLink,
 | 
			
		||||
				fmt.Sprintf("<a href=\"%s\">%s</a>", 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") {
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user