-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcomment.go
121 lines (95 loc) · 2.4 KB
/
comment.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
package godiff
import (
"regexp"
"time"
)
type UnixTimestamp int
func (u UnixTimestamp) String() string {
return time.Unix(int64(u/1000), 0).Format(time.ANSIC)
}
type Comment struct {
Id int64
Version int
Text string
CreatedDate UnixTimestamp
UpdatedDate UnixTimestamp
Comments CommentsTree
Author struct {
Name string
EmailAddress string
Id int
DisplayName string
Active bool
Slug string
Type string
}
Anchor CommentAnchor
PermittedOperations struct {
Editable bool
Deletable bool
}
Indent int
Parented bool
}
type CommentAnchor struct {
FromHash string
ToHash string
Line int64 `json:"line"`
LineType string `json:"lineType"`
Path string `json:"path"`
SrcPath string `json:"srcPath"`
FileType string `json:"fileType"`
}
type CommentsTree []*Comment
//const replyIndent = " "
var begOfLineRe = regexp.MustCompile("(?m)^")
//func (c Comment) String() string {
// comments, _ := commentTpl.Execute(c)
// for _, reply := range c.Comments {
// comments += reply.AsReply()
// }
// return comments
//}
//func (c Comment) AsReply() string {
// return begOfLineRe.ReplaceAllString(
// commentSpacing+c.String(),
// replyIndent,
// )
//}
var reWhiteSpace = regexp.MustCompile(`\s+`)
func (c Comment) Short(length int) string {
sticked := []rune(reWhiteSpace.ReplaceAllString(c.Text, " "))
if len(sticked) > length {
return string(sticked[:length]) + "..."
} else {
return string(sticked)
}
}
const ignorePrefix = "###"
var reBeginningOfLine = regexp.MustCompile(`(?m)^`)
var reIgnorePrefixSpace = regexp.MustCompile("(?m)^" + ignorePrefix + " $")
func Note(String string) string {
return reIgnorePrefixSpace.ReplaceAllString(
reBeginningOfLine.ReplaceAllString(String, ignorePrefix+" "),
ignorePrefix)
}
//const commentSpacing = "\n\n"
//const commentPrefix = "# "
//func (comments CommentsTree) String() string {
// res := ""
// if len(comments) > 0 {
// res = "---" + commentSpacing
// }
// for i, comment := range comments {
// res += comment.String()
// if i < len(comments)-1 {
// res += commentSpacing
// }
// }
// if len(comments) > 0 {
// return danglingSpacesRe.ReplaceAllString(
// begOfLineRe.ReplaceAllString(res, "# "), "")
// } else {
// return ""
// }
//}