-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathformat.go
92 lines (76 loc) · 1.7 KB
/
format.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
package main
import (
"strings"
"github.com/hhhapz/doc"
)
func typdef(def string, full bool) (string, bool) {
split := strings.Split(def, "\n")
// Show upto 8 lines, good for single-line interfaces and the sort.
if len(split) <= 8 {
return def, false
}
// More than one line, but there is more declaration
if !full {
return split[0], true
}
b := strings.Builder{}
b.Grow(len(def))
var more bool
for _, line := range strings.Split(def, "\n") {
b.WriteRune('\n')
if len(line)+b.Len() > defLimit {
b.WriteString("// full signature omitted")
more = true
break
}
b.WriteString(line)
}
return b.String(), more
}
func comment(c doc.Comment, initial int, full bool) (string, bool) {
if len(c) == 0 {
return "*No documentation found*", false
}
limit := docLimit
if !full {
limit = shortDocLimit
}
// if !full {
// if md := c.Markdown(); len(md) < 500 {
// return md, false
// }
// md, more := c[0].Markdown(), len(c) > 1
// if len(md) > 600 {
// md = md[:500]
// more = true
// }
// if more {
// md += "...\n\n*More documentation omitted*"
// }
// return md, more
// }
var parts doc.Comment
var more bool
length := initial
for i, note := range c {
if _, ok := note.(doc.Pre); !full && ok {
parts = append(parts, doc.Paragraph("*More documentation omitted...*"))
more = true
break
}
if i > 3 && !full {
parts = append(parts, doc.Paragraph("*More documentation omitted...*"))
more = true
break
}
l := len(note.Text())
if l+length > limit {
parts = append(parts, doc.Paragraph("*More documentation omitted...*"))
more = true
break
}
length += l
parts = append(parts, note)
}
return parts.Markdown(), more
}