link parsing implemented
This commit is contained in:
parent
64227f3a16
commit
341878e8e2
13
main.go
13
main.go
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue