Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(925)

Side by Side Diff: pkg/present/link.go

Issue 6847128: code review 6847128: go.talks/pkg/present: Adding inline links with style. (Closed)
Patch Set: diff -r ed69caf364d5 https://code.google.com/p/go.talks Created 11 years, 4 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2012 The Go Authors. All rights reserved. 1 // Copyright 2012 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style 2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file. 3 // license that can be found in the LICENSE file.
4 4
5 package present 5 package present
6 6
7 import ( 7 import (
8 "fmt" 8 "fmt"
9 "html/template" 9 "html/template"
10 "net/url" 10 "net/url"
11 "regexp"
11 "strings" 12 "strings"
12 ) 13 )
13 14
14 func init() { 15 func init() {
15 Register("link", parseLink, link) 16 Register("link", parseLink, link)
16 } 17 }
17 18
18 type Link struct { 19 type Link struct {
19 URL *url.URL 20 URL *url.URL
20 Args []string 21 Args []string
(...skipping 18 matching lines...) Expand all
39 switch len(arg) { 40 switch len(arg) {
40 case 0: 41 case 0:
41 scheme := url.Scheme + "://" 42 scheme := url.Scheme + "://"
42 if url.Scheme == "mailto" { 43 if url.Scheme == "mailto" {
43 scheme = "mailto:" 44 scheme = "mailto:"
44 } 45 }
45 label = strings.Replace(url.String(), scheme, "", 1) 46 label = strings.Replace(url.String(), scheme, "", 1)
46 default: 47 default:
47 label = strings.Join(arg, " ") 48 label = strings.Join(arg, " ")
48 } 49 }
49 return template.HTML(fmt.Sprintf(`<a href=%q>%s</a>`, url.String(), labe l)), nil 50 return template.HTML(fmt.Sprintf(`<a href=%q>%s</a>`, url.String(), labe l)), nil
adg 2012/12/01 11:41:20 change this to return template.HTML(renderLink(u
francesc 2012/12/01 20:53:58 Done.
50 } 51 }
52
53 var inlineExp = regexp.MustCompile(`^\[\[([^\[\]]+)\](\[([^\[\]]*)\])?\]`)
adg 2012/12/01 11:41:20 Gross regexp. Please read: http://commandcenter.
francesc 2012/12/01 20:53:58 Done, but removed the check after finding urlEnd,
54
55 func isInlineLink(text string) bool {
56 return inlineExp.MatchString(text)
57 }
58
59 func findInlineLink(text string, start int) (int, int, bool) {
60 if f := inlineExp.FindString(text[start:]); f != "" {
61 return start, start + len(f), true
62 }
63 return 0, 0, false
64 }
65
66 func parseInlineLink(text string) string {
67 s := inlineExp.FindStringSubmatch(text)
68 url, text := s[1], font(s[3])
69 if text == "" {
70 text = url
71 }
72 return fmt.Sprintf(`<a href=%q>%s</a>`, url, text)
73 }
OLDNEW
« no previous file with comments | « pkg/present/doc.go ('k') | pkg/present/style.go » ('j') | pkg/present/style.go » ('J')

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b