Skip to content
This repository was archived by the owner on Jul 29, 2021. It is now read-only.

Commit a8ca721

Browse files
author
Kun Devanny
committed
Add bitscape, kebab functions to aid with bitbucket specific formatting
1 parent e7bb543 commit a8ca721

File tree

2 files changed

+45
-30
lines changed

2 files changed

+45
-30
lines changed

main.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ var (
6060
"base": path.Base,
6161
"md": mdFunc,
6262
"pre": preFunc,
63+
"kebab": kebabFunc,
64+
"bitscape": bitscapeFunc, //Escape [] for bitbucket confusion
6365
}
6466
)
6567

@@ -90,6 +92,19 @@ func readTemplate(name, data string) *template.Template {
9092
return t
9193
}
9294

95+
func kebabFunc(text string) string {
96+
s := strings.Replace(strings.ToLower(text), " ", "-", -1)
97+
s = strings.Replace(s, ".", "-", -1)
98+
s = strings.Replace(s, "\\*", "42", -1)
99+
return s
100+
}
101+
102+
func bitscapeFunc(text string) string {
103+
s := strings.Replace(text, "[", "\\[", -1)
104+
s = strings.Replace(s, "]", "\\]", -1)
105+
return s
106+
}
107+
93108
func main() {
94109
flag.Usage = usage
95110
flag.Parse()

template.go

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,76 +6,76 @@ var pkgTemplate = `{{with .PDoc}}
66
{{comment_md .Doc}}
77
{{else}}
88
# {{ .Name }}
9-
` + "`" + `import "{{.ImportPath}}"` + "`" + `
109
11-
* [Overview](#pkg-overview)
12-
* [Index](#pkg-index){{if $.Examples}}
13-
* [Examples](#pkg-examples){{- end}}{{if $.Dirs}}
14-
* [Subdirectories](#pkg-subdirectories){{- end}}
10+
* [Overview](#markdown-header-overview)
11+
* [Index](#markdown-header-index){{if $.Examples}}
12+
* [Examples](#markdown-header-examples){{- end}}{{if $.Dirs}}
13+
* [Subdirectories](#markdown-header-subdirectories){{- end}}
1514
16-
## <a name="pkg-overview">Overview</a>
15+
## Overview
1716
{{comment_md .Doc}}
1817
{{example_html $ ""}}
18+
{{example_text $ "" " "}}
1919
20-
## <a name="pkg-index">Index</a>{{if .Consts}}
21-
* [Constants](#pkg-constants){{end}}{{if .Vars}}
22-
* [Variables](#pkg-variables){{end}}{{- range .Funcs -}}{{$name_html := html .Name}}
23-
* [{{node_html $ .Decl false | sanitize}}](#{{$name_html}}){{- end}}{{- range .Types}}{{$tname_html := html .Name}}
24-
* [type {{$tname_html}}](#{{$tname_html}}){{- range .Funcs}}{{$name_html := html .Name}}
25-
* [{{node_html $ .Decl false | sanitize}}](#{{$name_html}}){{- end}}{{- range .Methods}}{{$name_html := html .Name}}
26-
* [{{node_html $ .Decl false | sanitize}}](#{{$tname_html}}.{{$name_html}}){{- end}}{{- end}}{{- if $.Notes}}{{- range $marker, $item := $.Notes}}
27-
* [{{noteTitle $marker | html}}s](#pkg-note-{{$marker}}){{end}}{{end}}
20+
## Index{{if .Consts}}
21+
* [Constants](#markdown-header-constants){{end}}{{if .Vars}}
22+
* [Variables](#markdown-header-variables){{end}}{{- range .Funcs -}}{{$name_html := html .Name}}
23+
* [{{node_html $ .Decl false | sanitize | bitscape}}](#markdown-header-{{node_html $ .Decl false | sanitize | kebab}}){{- end}}{{- range .Types}}{{$tname_html := html .Name}}
24+
* [type {{$tname_html}}](#markdown-header-type-{{kebab $tname_html}}){{- range .Funcs}}{{$name_html := html .Name}}
25+
* [{{node_html $ .Decl false | sanitize | bitscape}}](#markdown-header-func-{{$name_html | kebab}}){{- end}}{{- range .Methods}}{{$name_html := html .Name}}
26+
* [{{node_html $ .Decl false | sanitize | bitscape}}](#markdown-header-func-{{md .Recv | kebab}}-{{$name_html | kebab}}){{- end}}{{- end}}{{- if $.Notes}}{{- range $marker, $item := $.Notes}}
27+
* [{{noteTitle $marker | html}}s](#markdown-header-{{noteTitle $marker | html | kebab}}s}}){{end}}{{end}}
2828
{{if $.Examples}}
29-
#### <a name="pkg-examples">Examples</a>{{- range $.Examples}}
30-
* [{{example_name .Name}}](#example_{{.Name}}){{- end}}{{- end}}
29+
#### Examples{{- range $.Examples}}
30+
* [{{example_name .Name}}]{{- end}}{{- end}}
3131
{{with .Filenames}}
32-
#### <a name="pkg-files">Package files</a>
33-
{{range .}}[{{.|filename|html}}]({{.|srcLink|html}}) {{end}}
32+
#### Package files
33+
{{range .}}[{{.|filename|html}}]{{end}}
3434
{{end}}
3535
36-
{{with .Consts}}## <a name="pkg-constants">Constants</a>
36+
{{with .Consts}}## Constants
3737
{{range .}}{{node $ .Decl | pre}}
3838
{{comment_md .Doc}}{{end}}{{end}}
39-
{{with .Vars}}## <a name="pkg-variables">Variables</a>
39+
{{with .Vars}}## Variables
4040
{{range .}}{{node $ .Decl | pre}}
4141
{{comment_md .Doc}}{{end}}{{end}}
4242
43-
{{range .Funcs}}{{$name_html := html .Name}}## <a name="{{$name_html}}">func</a> [{{$name_html}}]({{posLink_url $ .Decl}})
43+
{{range .Funcs}}{{$name_html := html .Name}}## func [{{$name_html}}]
4444
{{node $ .Decl | pre}}
4545
{{comment_md .Doc}}
46-
{{example_html $ .Name}}
46+
{{example_text $ .Name " "}}
4747
{{callgraph_html $ "" .Name}}{{end}}
48-
{{range .Types}}{{$tname := .Name}}{{$tname_html := html .Name}}## <a name="{{$tname_html}}">type</a> [{{$tname_html}}]({{posLink_url $ .Decl}})
48+
{{range .Types}}{{$tname := .Name}}{{$tname_html := html .Name}}## type [{{$tname_html}}]
4949
{{node $ .Decl | pre}}
5050
{{comment_md .Doc}}{{range .Consts}}
5151
{{node $ .Decl | pre }}
5252
{{comment_md .Doc}}{{end}}{{range .Vars}}
5353
{{node $ .Decl | pre }}
5454
{{comment_md .Doc}}{{end}}
5555
56-
{{example_html $ $tname}}
56+
{{example_text $ $tname " "}}
5757
{{implements_html $ $tname}}
5858
{{methodset_html $ $tname}}
5959
60-
{{range .Funcs}}{{$name_html := html .Name}}### <a name="{{$name_html}}">func</a> [{{$name_html}}]({{posLink_url $ .Decl}})
60+
{{range .Funcs}}{{$name_html := html .Name}}### func [{{$name_html}}]
6161
{{node $ .Decl | pre}}
6262
{{comment_md .Doc}}
63-
{{example_html $ .Name}}{{end}}
63+
{{example_text $ .Name " "}}{{end}}
6464
{{callgraph_html $ "" .Name}}
6565
66-
{{range .Methods}}{{$name_html := html .Name}}### <a name="{{$tname_html}}.{{$name_html}}">func</a> ({{md .Recv}}) [{{$name_html}}]({{posLink_url $ .Decl}})
66+
{{range .Methods}}{{$name_html := html .Name}}### func ({{md .Recv}}) [{{$name_html}}]
6767
{{node $ .Decl | pre}}
6868
{{comment_md .Doc}}
69-
{{$name := printf "%s_%s" $tname .Name}}{{example_html $ $name}}
69+
{{$name := printf "%s_%s" $tname .Name}}{{example_text $ $name " "}}
7070
{{callgraph_html $ .Recv .Name}}
7171
{{end}}{{end}}{{end}}
7272
7373
{{with $.Notes}}
7474
{{range $marker, $content := .}}
75-
## <a name="pkg-note-{{$marker}}">{{noteTitle $marker | html}}s
75+
## {{noteTitle $marker | html}}s
7676
<ul style="list-style: none; padding: 0;">
7777
{{range .}}
78-
<li><a href="{{posLink_url $ .}}">&#x261e;</a> {{html .Body}}</li>
78+
<li>&#x261e; {{html .Body}}</li>
7979
{{end}}
8080
</ul>
8181
{{end}}

0 commit comments

Comments
 (0)