go.tools/present: links with the prefix "javascript:" should be executed in the same window.
Using url.Parse instead of more ad hoc solution. R=r CC=golang-codereviews https://golang.org/cl/47320043
This commit is contained in:
parent
822669c658
commit
5f5d42a466
|
|
@ -6,6 +6,7 @@ package present
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net/url"
|
||||
"strings"
|
||||
)
|
||||
|
|
@ -40,18 +41,20 @@ func parseLink(ctx *Context, fileName string, lineno int, text string) (Elem, er
|
|||
return Link{url, label}, nil
|
||||
}
|
||||
|
||||
func renderLink(url, text string) string {
|
||||
func renderLink(href, text string) string {
|
||||
text = font(text)
|
||||
if text == "" {
|
||||
text = url
|
||||
text = href
|
||||
}
|
||||
// Open links in new window only when their url is absolute.
|
||||
target := "_blank"
|
||||
if url[0] == '/' {
|
||||
if u, err := url.Parse(href); err != nil {
|
||||
log.Println("rendernLink parsing url: %v", err)
|
||||
} else if !u.IsAbs() || u.Scheme == "javascript" {
|
||||
target = "_self"
|
||||
}
|
||||
|
||||
return fmt.Sprintf(`<a href="%s" target="%s">%s</a>`, url, target, text)
|
||||
return fmt.Sprintf(`<a href="%s" target="%s">%s</a>`, href, target, text)
|
||||
}
|
||||
|
||||
// parseInlineLink parses an inline link at the start of s, and returns
|
||||
|
|
|
|||
Loading…
Reference in New Issue