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"
"fmt"
"bufio"
"strings"
)
type hlink struct {
@ -39,6 +40,14 @@ func text2link(text string, url string) string {
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) {
f, _ := os.Create(title + ".html")
f.WriteString(head)
@ -79,8 +88,8 @@ func fparse(fname string) Game{
game.Pages = append(game.Pages, Page{Body:cutFirstWord(line)})
fmt.Println(cutFirstWord(line))
case string(line[0]) == "-":
game.Pages[pcount]:Links = append
//fmt.Println("New link")
newLink := line2link(line)
game.Pages[pcount].Links = append(game.Pages[pcount].Links, newLink)
}
//fmt.Println(firstchar)