go.tools/present: Open links with local (non absolute) URLs in the same window.

This allows having links from one slide to another one in the same presentation.
Also it is needed in the new tour to cross reference lessons.

R=r
CC=golang-codereviews
https://golang.org/cl/46130043
This commit is contained in:
Francesc Campoy 2013-12-28 21:10:40 -08:00
parent 30645c4bc6
commit 3d2d158b9d
1 changed files with 7 additions and 1 deletions

View File

@ -45,7 +45,13 @@ func renderLink(url, text string) string {
if text == "" {
text = url
}
return fmt.Sprintf(`<a href="%s" target="_blank">%s</a>`, url, text)
// Open links in new window only when their url is absolute.
target := "_blank"
if url[0] == '/' {
target = "_self"
}
return fmt.Sprintf(`<a href="%s" target="%s">%s</a>`, url, target, text)
}
// parseInlineLink parses an inline link at the start of s, and returns