-
Notifications
You must be signed in to change notification settings - Fork 6
/
hyperlink.go
54 lines (46 loc) · 1020 Bytes
/
hyperlink.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package span
import (
"fmt"
"github.com/SoCloz/goprismic/fragment/link"
)
type Hyperlink struct {
Span
Link link.Link
}
func (s *Hyperlink) Decode(enc interface{}) error {
err := s.decodeSpan(enc)
if err != nil {
return err
}
dec, ok := enc.(map[string]interface{})
if !ok {
return fmt.Errorf("%+v is not a map", enc)
}
v, found := dec["data"]
if !found {
return fmt.Errorf("No data found for link %+v", enc)
}
dec, ok = v.(map[string]interface{})
if !ok {
return fmt.Errorf("%+v is not a map", v)
}
t, found := dec["type"]
if !found {
return fmt.Errorf("No type found for link %+v", v)
}
l, foundlink := dec["value"]
if !foundlink {
err = fmt.Errorf("No link value found in %+v", enc)
}
s.Link, err = link.Decode(t.(string), l)
return err
}
func (h *Hyperlink) HtmlBeginTag() string {
return fmt.Sprintf("<a href=\"%s\">", h.Link.GetUrl())
}
func (h *Hyperlink) HtmlEndTag() string {
return "</a>"
}
func (h *Hyperlink) ResolveLinks(r link.Resolver) {
h.Link.Resolve(r)
}