diff options
author | Dimitri Sokolyuk <demon@dim13.org> | 2015-07-10 14:26:36 +0200 |
---|---|---|
committer | Dimitri Sokolyuk <demon@dim13.org> | 2015-07-10 14:26:36 +0200 |
commit | bc97efd506df415243d0d6a13a4ec066de847ff8 (patch) | |
tree | 3191b85c996587ec03c310805960a363a39fb912 /href.go | |
parent | 1ea2e5c0937ef86b20a55b34d4a9a495b3dffa6a (diff) |
Fix multiline titles
Diffstat (limited to 'href.go')
-rw-r--r-- | href.go | 12 |
1 files changed, 7 insertions, 5 deletions
@@ -2,19 +2,21 @@ package main import ( "net/http" + "strings" "golang.org/x/net/html" ) -func findTitle(n *html.Node) string { +func findTitle(n *html.Node) (s string) { if n.Type == html.ElementNode && n.Data == "title" { - if c := n.FirstChild; n != nil { - return c.Data + for c := n.FirstChild; c != nil; c = c.NextSibling { + s += c.Data } + return strings.TrimSpace(s) } for c := n.FirstChild; c != nil; c = c.NextSibling { - if s := findTitle(c); s != "" { - return s + if t := findTitle(c); t != "" { + return t } } return "" |