Skip to content

Commit 8fb6f38

Browse files
committed
feat: add two regex for markdown linting
1 parent 1ee9a7e commit 8fb6f38

File tree

11 files changed

+36
-29
lines changed

11 files changed

+36
-29
lines changed

example-charts/custom-template/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Basically the same as the nginx-ingress chart, but using a custom template to in
55
Current chart version is `0.2.0`
66

77
## Additional Information
8+
89
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore
910
et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut
1011
aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse

example-charts/custom-template/README.md.gotmpl

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
{{ template "chart.versionLine" . }}
55

66
## Additional Information
7+
78
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore
89
et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut
910
aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse

example-charts/full-template/README.md

-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ https://github.com/norwoodj/helm-docs/tree/master/example-charts/full-template
7676

7777
## `chart.sourcesList`
7878

79-
8079
* <https://github.com/norwoodj/helm-docs/tree/master/example-charts/full-template>
8180

8281
## `chart.sourcesSection`

example-charts/full-template/README.md.gotmpl

+7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
{{ template "chart.header" . }}
22
## `chart.deprecationWarning`
33

4+
5+
6+
7+
8+
9+
10+
411
{{ template "chart.deprecationWarning" . }}
512

613
## `chart.description`

example-charts/helm-3/README.md

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
# nginx-ingress
22

3-
4-
5-
![Version: 0.2.0](https://img.shields.io/badge/Version-0.2.0-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square)
3+
![Version: 0.2.0](https://img.shields.io/badge/Version-0.2.0-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square)
64

75
A simple wrapper around the stable/nginx-ingress chart that adds a few of our conventions
86

example-charts/most-empty/README.md

-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
# most-empty
22

3-
4-
53
Current chart version is `0.2.0`
64

75
This is a good example of all the fields that don't appear when they aren't set in chart metadata. `description`,
86
`requirements`, and `values` are all empty and don't appear here.
97

10-
11-
12-

example-charts/nginx-ingress/README.md

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
# nginx-ingress
22

3-
4-
5-
![Version: 0.2.0](https://img.shields.io/badge/Version-0.2.0-informational?style=flat-square)
3+
![Version: 0.2.0](https://img.shields.io/badge/Version-0.2.0-informational?style=flat-square)
64

75
A simple wrapper around the stable/nginx-ingress chart that adds a few of our conventions
86

example-charts/no-requirements/README.md

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
# no-requirements
22

3-
4-
5-
![Version: 0.2.0](https://img.shields.io/badge/Version-0.2.0-informational?style=flat-square)
3+
![Version: 0.2.0](https://img.shields.io/badge/Version-0.2.0-informational?style=flat-square)
64

75
A simple chart that installs, let's say PrometheusRules, that needs no sub-charts
86

@@ -18,8 +16,6 @@ A simple chart that installs, let's say PrometheusRules, that needs no sub-chart
1816

1917
* <https://github.com/norwoodj/helm-docs/tree/master/example-charts/no-requirements>
2018

21-
22-
2319
## Values
2420

2521
| Key | Type | Default | Description |

example-charts/no-values/README.md

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
# no-values
22

3-
4-
5-
![Version: 0.2.0](https://img.shields.io/badge/Version-0.2.0-informational?style=flat-square)
3+
![Version: 0.2.0](https://img.shields.io/badge/Version-0.2.0-informational?style=flat-square)
64

75
A very simple chart that doesn't even need any values for customization
86

@@ -18,6 +16,3 @@ A very simple chart that doesn't even need any values for customization
1816

1917
* <https://github.com/norwoodj/helm-docs/tree/master/example-charts/no-values>
2018

21-
22-
23-

example-charts/special-characters/README.md

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
# special-characters
22

3-
4-
5-
![Version: 0.2.0](https://img.shields.io/badge/Version-0.2.0-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square)
3+
![Version: 0.2.0](https://img.shields.io/badge/Version-0.2.0-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square)
64

75
A chart demonstrating handling of special characters in values files
86

@@ -18,8 +16,6 @@ A chart demonstrating handling of special characters in values files
1816

1917
* <https://github.com/norwoodj/helm-docs/tree/master/example-charts/special-characters>
2018

21-
22-
2319
## Values
2420

2521
| Key | Type | Default | Description |

pkg/document/generate.go

+22-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package document
22

33
import (
4+
"bytes"
45
"fmt"
56
"os"
67
"path/filepath"
8+
"regexp"
79

810
"github.com/norwoodj/helm-docs/pkg/helm"
911
log "github.com/sirupsen/logrus"
@@ -50,8 +52,27 @@ func PrintDocumentation(chartDocumentationInfo helm.ChartDocumentationInfo, dryR
5052
defer outputFile.Close()
5153
}
5254

53-
err = chartDocumentationTemplate.Execute(outputFile, chartTemplateDataObject)
55+
var output bytes.Buffer
56+
err = chartDocumentationTemplate.Execute(&output, chartTemplateDataObject)
5457
if err != nil {
5558
log.Warnf("Error generating documentation for chart %s: %s", chartDocumentationInfo.ChartDirectory, err)
5659
}
60+
output = applyMarkDownFormat(output)
61+
_, err = output.WriteTo(outputFile)
62+
if err != nil {
63+
log.Warnf("Error generating documentation file for chart %s: %s", chartDocumentationInfo.ChartDirectory, err)
64+
}
65+
}
66+
67+
func applyMarkDownFormat(output bytes.Buffer) bytes.Buffer {
68+
outputString := output.String()
69+
re := regexp.MustCompile(` \n`)
70+
outputString = re.ReplaceAllString(outputString, "\n")
71+
72+
re = regexp.MustCompile(`\n{3,}`)
73+
outputString = re.ReplaceAllString(outputString, "\n\n")
74+
75+
output.Reset()
76+
output.WriteString(outputString)
77+
return output
5778
}

0 commit comments

Comments
 (0)