/
format.go
49 lines (40 loc) · 908 Bytes
/
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
package format
import (
"fmt"
"io"
"strings"
"text/template"
"github.com/k1LoW/frgm/snippet"
)
type Loader interface {
Load(src string) (snippet.Snippets, error)
}
type Exporter interface {
Export(snippets snippet.Snippets, dest string) error
}
type Decoder interface {
Decode(in io.Reader, group string) (snippet.Snippets, error)
}
type Encoder interface {
Encode(out io.Writer, snippets snippet.Snippets) error
}
type Exts []string
func (exts Exts) Contains(t string) bool {
for _, e := range exts {
if e == t {
return true
}
}
return false
}
func Funcs() map[string]interface{} {
return template.FuncMap{
"nl2mdnl": func(text string) string {
r := strings.NewReplacer("\r\n", " \n", "\n", " \n", "\r", " \n")
return r.Replace(text)
},
"label_join": func(l []string) string {
return fmt.Sprintf("<code>%s</code>", strings.Join(l, "</code> <code>"))
},
}
}