Skip to content

Commit dede182

Browse files
committed
improved multi-line support in mardown table
1 parent e4ee407 commit dede182

4 files changed

Lines changed: 29 additions & 9 deletions

File tree

cmd/helm-values/internal/commands/docs.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,9 +188,28 @@ func schemaProperties(schema *jsonschema.Schema, parents []string) []docs.Values
188188
fmt.Printf("Error marshaling default value for key %s: %v\n", key, err)
189189
}
190190

191+
typeValue := prop.Type
192+
if len(prop.Enum) > 0 {
193+
enumItems := make([]string, len(prop.Enum))
194+
for i, enumItem := range prop.Enum {
195+
enumBytes, err := json.Marshal(enumItem)
196+
if err != nil {
197+
// TODO: Handle this error better
198+
continue
199+
}
200+
enumItems[i] = string(enumBytes)
201+
}
202+
203+
typeValue = fmt.Sprintf(
204+
"%s (enum)\n%s",
205+
typeValue,
206+
strings.Join(enumItems, ", "),
207+
)
208+
}
209+
191210
row := docs.ValuesRow{
192211
Key: strings.Join(append(parents, key), "."),
193-
Type: prop.Type,
212+
Type: typeValue,
194213
Default: string(defaultStr),
195214
Description: prop.Description,
196215
}

cmd/helm-values/internal/docs/templates.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ func (b *TemplateBuilder) Build(fsys fs.FS) (*template.Template, error) {
8484
funcMap["maxLen"] = maxLen
8585
funcMap["rowSelect"] = rowSelect
8686
funcMap["mdRow"] = mdRow
87+
funcMap["mdMultiline"] = mdMultiline
8788

8889
return template.New(b.TemplateName()).
8990
Funcs(funcMap).
Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
11

22
{{- define "md.valuesTable" }}
3-
{{ $cwKey := add (maxLen (rowSelect .ValuesTable "Key")) 1 }}
4-
{{ $cwType := add (maxLen (rowSelect .ValuesTable "Type")) 1 }}
5-
{{ $cwDefault := add (maxLen (rowSelect .ValuesTable "Default")) 1 }}
6-
{{ $cwDescription := add (maxLen (rowSelect .ValuesTable "Description")) 1 }}
73

84
| Key | Type | Default | Description |
95
|-----|------|---------|-------------|
106
{{- range .ValuesTable }}
117
{{- "\n" }}
12-
{{- printf "| %s" (rpad .Key " " $cwKey) }}
13-
{{- printf "| %s" (rpad .Type " " $cwType) }}
14-
{{- printf "| %s" (rpad .Default " " $cwDefault) }}
15-
{{- printf "| %s" (rpad (.Description | replace "\n" "<br>") " " $cwDescription) }}
8+
{{- printf "| %s " (mdMultiline .Key) }}
9+
{{- printf "| %s " (mdMultiline .Type) }}
10+
{{- printf "| `%s` " (mdMultiline .Default) }}
11+
{{- printf "| %s " (mdMultiline .Description) }}
1612
{{- "|" }}
1713
{{- end }}
1814
{{- end }}

cmd/helm-values/internal/docs/tmpl_funcs.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,7 @@ func mdRow(cols []string, colWidths []int64) string {
5858

5959
return fmt.Sprintf("| %s |", strings.Join(c, " | "))
6060
}
61+
62+
func mdMultiline(s string) string {
63+
return strings.ReplaceAll(s, "\n", "</br>")
64+
}

0 commit comments

Comments
 (0)