Skip to content

Commit

Permalink
feat: add two regex for markdown linting
Browse files Browse the repository at this point in the history
  • Loading branch information
Artus-LHIND committed May 15, 2020
1 parent 1ee9a7e commit 8fb6f38
Show file tree
Hide file tree
Showing 11 changed files with 36 additions and 29 deletions.
1 change: 1 addition & 0 deletions example-charts/custom-template/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Basically the same as the nginx-ingress chart, but using a custom template to in
Current chart version is `0.2.0`

## Additional Information

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore
et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut
aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
Expand Down
1 change: 1 addition & 0 deletions example-charts/custom-template/README.md.gotmpl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
{{ template "chart.versionLine" . }}

## Additional Information

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore
et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut
aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
Expand Down
1 change: 0 additions & 1 deletion example-charts/full-template/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ https://github.com/norwoodj/helm-docs/tree/master/example-charts/full-template

## `chart.sourcesList`


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

## `chart.sourcesSection`
Expand Down
7 changes: 7 additions & 0 deletions example-charts/full-template/README.md.gotmpl
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
{{ template "chart.header" . }}
## `chart.deprecationWarning`








{{ template "chart.deprecationWarning" . }}

## `chart.description`
Expand Down
4 changes: 1 addition & 3 deletions example-charts/helm-3/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# nginx-ingress



![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)
![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)

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

Expand Down
5 changes: 0 additions & 5 deletions example-charts/most-empty/README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
# most-empty



Current chart version is `0.2.0`

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




4 changes: 1 addition & 3 deletions example-charts/nginx-ingress/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# nginx-ingress



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

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

Expand Down
6 changes: 1 addition & 5 deletions example-charts/no-requirements/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# no-requirements



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

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

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

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



## Values

| Key | Type | Default | Description |
Expand Down
7 changes: 1 addition & 6 deletions example-charts/no-values/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# no-values



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

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

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

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




6 changes: 1 addition & 5 deletions example-charts/special-characters/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# special-characters



![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)
![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)

A chart demonstrating handling of special characters in values files

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

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



## Values

| Key | Type | Default | Description |
Expand Down
23 changes: 22 additions & 1 deletion pkg/document/generate.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package document

import (
"bytes"
"fmt"
"os"
"path/filepath"
"regexp"

"github.com/norwoodj/helm-docs/pkg/helm"
log "github.com/sirupsen/logrus"
Expand Down Expand Up @@ -50,8 +52,27 @@ func PrintDocumentation(chartDocumentationInfo helm.ChartDocumentationInfo, dryR
defer outputFile.Close()
}

err = chartDocumentationTemplate.Execute(outputFile, chartTemplateDataObject)
var output bytes.Buffer
err = chartDocumentationTemplate.Execute(&output, chartTemplateDataObject)
if err != nil {
log.Warnf("Error generating documentation for chart %s: %s", chartDocumentationInfo.ChartDirectory, err)
}
output = applyMarkDownFormat(output)
_, err = output.WriteTo(outputFile)
if err != nil {
log.Warnf("Error generating documentation file for chart %s: %s", chartDocumentationInfo.ChartDirectory, err)
}
}

func applyMarkDownFormat(output bytes.Buffer) bytes.Buffer {
outputString := output.String()
re := regexp.MustCompile(` \n`)
outputString = re.ReplaceAllString(outputString, "\n")

re = regexp.MustCompile(`\n{3,}`)
outputString = re.ReplaceAllString(outputString, "\n\n")

output.Reset()
output.WriteString(outputString)
return output
}

0 comments on commit 8fb6f38

Please sign in to comment.