From bc97efd506df415243d0d6a13a4ec066de847ff8 Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Fri, 10 Jul 2015 14:26:36 +0200 Subject: Fix multiline titles --- href.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'href.go') 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 "" -- cgit v1.2.3