-
Notifications
You must be signed in to change notification settings - Fork 4
/
helper.go
75 lines (60 loc) · 1.61 KB
/
helper.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package md
import (
"fmt"
)
// 仅支持部分
// 语法详情: https://open.feishu.cn/document/ukTMukTMukTM/uADOwUjLwgDM14CM4ATN
func Italics(s string) string {
return fmt.Sprintf("*%s*", s)
}
func Bold(s string) string {
return fmt.Sprintf("**%s**", s)
}
func Strikethrough(s string) string {
return fmt.Sprintf("~~%s~~", s)
}
func Link(url string) string {
return fmt.Sprintf("<a>%s</a>", url)
}
func TextLink(text, url string) string {
return fmt.Sprintf("[%s](%s)", text, url)
}
func Image(hoverText, imageKey string) string {
return "!" + TextLink(hoverText, imageKey)
}
func HorizontalRule() string {
return ` ---`
}
// MentionByID 通过 Open ID 或 User ID @指定人
//
// 如果 ID 无效,则取 name 展示
//
// https://open.feishu.cn/document/ukTMukTMukTM/ucTM5YjL3ETO24yNxkjN#e1cdee9f
func MentionByID(id string, name ...string) string {
var s string
if len(name) != 0 {
s = name[0]
}
return fmt.Sprintf(`<at id=%s>%s</at>`, id, s)
}
// MentionByEmail 通过邮箱 @指定人
//
// https://open.feishu.cn/document/ugTN1YjL4UTN24CO1UjN/uUzN1YjL1cTN24SN3UjN?from=mcb#acc98e1b
func MentionByEmail(email string) string {
return fmt.Sprintf(`<at email=%s></at>`, email)
}
// MentionAll @所有人
//
// https://open.feishu.cn/document/ukTMukTMukTM/ucTM5YjL3ETO24yNxkjN#e1cdee9f
func MentionAll() string {
return `<at id=all></at>`
}
func ColorGreen(s string) string {
return fmt.Sprintf(`<font color='green'>%s</font>`, s)
}
func ColorRed(s string) string {
return fmt.Sprintf(`<font color='red'>%s</font>`, s)
}
func ColorGrey(s string) string {
return fmt.Sprintf(`<font color='grey'>%s</font>`, s)
}