Skip to content

Commit

Permalink
session-10: add comment
Browse files Browse the repository at this point in the history
  • Loading branch information
Py Explorer committed Feb 8, 2024
1 parent fbb91d6 commit 70f9d43
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion link/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func main() {
}

func parseUserInput() *string {
htmlFilePath := flag.String("file", "", "Path to the HTML file")
htmlFilePath := flag.String("file", "ex2.html", "Path to the HTML file")
flag.Parse()

if *htmlFilePath == "" {
Expand All @@ -53,6 +53,8 @@ func parseLinks(file os.File) []Link {
tokenizer := html.NewTokenizer(&file)
var links []Link
var buffer bytes.Buffer
// we can use string here as well
// var text string
var catchText bool
var link Link

Expand All @@ -76,13 +78,15 @@ func parseLinks(file os.File) []Link {
} else if tokenType == html.TextToken {
if catchText {
buffer.Write(tokenizer.Raw())
// text += string(tokenizer.Raw())
}
} else if tokenType == html.EndTagToken {
token := tokenizer.Token()
if token.DataAtom.String() == "a" {
link.Text = strings.TrimSpace(buffer.String())
links = append(links, link)
buffer.Reset()
// text = ""
catchText = false
}
}
Expand Down

0 comments on commit 70f9d43

Please sign in to comment.