summaryrefslogtreecommitdiff
path: root/href.go
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2015-07-10 14:26:36 +0200
committerDimitri Sokolyuk <demon@dim13.org>2015-07-10 14:26:36 +0200
commitbc97efd506df415243d0d6a13a4ec066de847ff8 (patch)
tree3191b85c996587ec03c310805960a363a39fb912 /href.go
parent1ea2e5c0937ef86b20a55b34d4a9a495b3dffa6a (diff)
Fix multiline titles
Diffstat (limited to 'href.go')
-rw-r--r--href.go12
1 files changed, 7 insertions, 5 deletions
diff --git a/href.go b/href.go
index 9ba955f..3a9239f 100644
--- a/href.go
+++ b/href.go
@@ -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 ""