You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add test files:
- Test custom overrides
- Test hyperlinks
- Test hyperlinks to value
Improvements:
- Add description about the hyperlinks
- Add more sample in the README.md
- Add support for multiline description sections
- Modify comment continuation regex
Copy file name to clipboardExpand all lines: README.md
+81
Original file line number
Diff line number
Diff line change
@@ -177,6 +177,9 @@ can be used as well:
177
177
| chart.valuesHeader | The heading for the chart values section |
178
178
| chart.valuesTable | A table of the chart's values parsed from the `values.yaml` file (see below) |
179
179
| chart.valuesSection | A section headed by the valuesHeader from above containing the valuesTable from above or "" if there are no values |
180
+
| chart.valuesTableHtml | Like `chart.valuesTable` but it is rendered as (X)HTML tags to allow further rendering customization, instead of markdown tables format. |
181
+
| chart.valuesSectionHtml | Like `chart.valuesSection` but uses `chart.valuesTableHtml` |
182
+
| chart.valueDefaultColumnRender | This is a hook template if you want to redefine how helm-docs render the default values in `chart.valuesTableHtml` mode. This is especially useful when combined with (X)HTML tags, so that you can nicely format multiline default values, like YAML/JSON object tree snippet with codeblock syntax highlighter, which is not possible or difficult when using the markdown table format. It can be redefined in your template file. |
180
183
181
184
The default internal template mentioned above uses many of these and looks like this:
182
185
```
@@ -333,3 +336,81 @@ configMap:
333
336
# configMap."not real config param" -- A completely fake config parameter for a useful example
334
337
not real config param: value
335
338
```
339
+
340
+
### Advanced table rendering
341
+
Some helm chart `values.yaml` uses complicated structure for the key/value
342
+
pairs. For example, it may uses a multiline string of Go template text instead
343
+
of plain strings. Some values might also refer to a certain YAML/JSON object
344
+
structure, like internal k8s value type, or an enum. For these use case,
345
+
a standard markdown table format might be inadequate and you want to use HTML
346
+
tags to render the table.
347
+
348
+
Some example use case on why you need advanced table rendering:
349
+
350
+
- Hyperlinking the value type to an anchor or HTML link somewhere for reference
351
+
- Collapsible value description using `<summary>` tags to save space
352
+
- Multiline default values as codeblocks, instead of one line JSON structure for readability
353
+
- Custom rendering, for colors, actions, bookmarking, cross-reference, etc
354
+
- Cascading the markdown file generated by helm-docs to be post-processed by Jamstack into a static HTML docs site.
355
+
356
+
In order to accomodate this, `helm-docs` provides an extensible and flexible way to customize rendering.
357
+
358
+
1. Use the HTML value renderer instead of the default markdown format
359
+
360
+
You can use `chart.valuesSectionHtml` to render the values table as HTML tags,
361
+
instead of using `chart.valuesSection`. Using HTML tables provides more
362
+
flexibility because it can be processed by markdown viewer as a nested blocks,
363
+
instead of one row per line. This allows you to customize how each columns in a
364
+
row are rendered.
365
+
366
+
2. Overriding built-in templates
367
+
368
+
You can always overrides or redefine built-in templates in your own `_templates.
369
+
gotmpl` file. The built-in templates can be thought of as a template hook.
370
+
For example, if you need to change the HTML table, for example to add a new
371
+
column, or define maximum width/height, you can override `chart.valuesTableHtml`. Your overrides will then be called by `chart.valuesSectionHtml`.
372
+
373
+
You can add your own rendering logic for each column. For example, we have `chart.valueDefaultColumnRender` that is used to render "default value" column for each rows. If you want to override how helm-docs render the
374
+
"type"column, just define your own rendering template and call it from
375
+
`chart.valuesTableHtml`for each of the rows.
376
+
377
+
3. Using the metadata of each rows of values
378
+
379
+
Custom styling and rendering can be done as flexible as you want, but you
380
+
still need a metadata that describes each rows of values. You can access
381
+
this information from the templates.
382
+
383
+
When you override `chart.valuesTableHtml`, as you can see in the original
384
+
definition in `func getValuesTableTemplates()` [pkg/document/template.go](pkg/document/template.go), we iterates each row of values.
385
+
For each "Value", it is modeled as a struct defined in `valueRow` struct
386
+
in [pkg/document/model.go](pkg/document/model.go). You can then use the
387
+
fields in your template.
388
+
389
+
Some fields here are directly referenced from `values.yaml`:
390
+
- `Key`: the full name of the key referenced in `values.yaml`
391
+
- `Type`: the type of the value of the key in `values.yaml`. Can be automatically inferred from YAML structure, or annotated using `# -- (mytype)` where `mytype` can be any string that you refer as the type of the value.
392
+
- `NotationType`: the notation of the type used to render the default value. If `Type` refers to the data type of the value, then `NotationType` refers to **how** this value should be written/rendered by helm-docs. Generally helm-docs only remembers the notation type, but it was the writer's responsibility to make a template tag to render a specific notation type. Annotate the key with `# @notationType -- (mynotation)` where `mynotation` is an identifier to tell the renderer how to write the value.
393
+
- `Default`: this is the default value of the key, found from `values.yaml`. It is either inferred from the YAML structure or defined using `# @default -- my default value` annotation, in case you need to show other example values.
394
+
- `Description`: this is the description of the key/value, taken from the comments found in the `values.yaml` for the referred key.
395
+
- `LineNumber`: this is the line number associated with where the key is declared. You can use this to construct an anchor to the actual `values.yaml` file.
396
+
397
+
Note that helm-docs only provides these information, but the default behaviour is to always render it in plain Markdown file to be viewed locally.
398
+
399
+
4. Use markdown files generated by helm-docs as intermediary files to be processed further
400
+
401
+
Public helm charts sometimes needs to be published as static content
402
+
instead of just stored in a repository. This is needed for helm users to
403
+
be able to view or browse the chart options and dependencies.
404
+
405
+
It is often more than enough to just browse the chart values options on
406
+
git hosting that is able to render markdown files as a nice HTML page, like GitHub or GitLab.
407
+
However, for a certain use case, you may want to use your own
408
+
documentation generator to host or publish the output of helm-docs.
409
+
410
+
If you use some kind of Jamstack like Gatsby or Hugo, you can use the
411
+
output of helm-docs as an input for these doc generator. A typical use
412
+
case is to override helm-docs built-in template so that it renders a
413
+
markdown or markdownX files to be processed by Gatsby or Hugo into
414
+
a static Web/Javascript page.
415
+
416
+
For a more concrete examples on how to do these custom rendering, see [example here](./example-charts/custom-value-notation-type/README.md)
0 commit comments