link parsing implemented

This commit is contained in:
ed 2020-01-04 16:14:00 +01:00
parent 64227f3a16
commit 341878e8e2
1 changed files with 11 additions and 2 deletions

13
main.go
View File

@ -4,6 +4,7 @@ import (
"os" "os"
"fmt" "fmt"
"bufio" "bufio"
"strings"
) )
type hlink struct { type hlink struct {
@ -39,6 +40,14 @@ func text2link(text string, url string) string {
return " <a href=\"" + url + "\">" + text + "</a>" return " <a href=\"" + url + "\">" + text + "</a>"
} }
func line2link(line string) hlink {
sline := strings.Split(line," ")
url:= sline[0][1:] + ".html"
text := strings.Join(sline[1:]," ")
//return " <a href=\"" + url + "\">" + text + "</a>"
return hlink{url,text}
}
func writeHTML(title string, body string, links...hlink) { func writeHTML(title string, body string, links...hlink) {
f, _ := os.Create(title + ".html") f, _ := os.Create(title + ".html")
f.WriteString(head) f.WriteString(head)
@ -79,8 +88,8 @@ func fparse(fname string) Game{
game.Pages = append(game.Pages, Page{Body:cutFirstWord(line)}) game.Pages = append(game.Pages, Page{Body:cutFirstWord(line)})
fmt.Println(cutFirstWord(line)) fmt.Println(cutFirstWord(line))
case string(line[0]) == "-": case string(line[0]) == "-":
game.Pages[pcount]:Links = append newLink := line2link(line)
//fmt.Println("New link") game.Pages[pcount].Links = append(game.Pages[pcount].Links, newLink)
} }
//fmt.Println(firstchar) //fmt.Println(firstchar)