Skip to content

Add support for closed ATX headers in Markdown output #745

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cmd/markdown/markdown.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ func NewCommand(runtime *cli.Runtime, config *print.Config) *cobra.Command {

// flags
cmd.PersistentFlags().BoolVar(&config.Settings.Anchor, "anchor", true, "create anchor links")
cmd.PersistentFlags().BoolVar(&config.Settings.AtxClosed, "atx-closed", false, "close ATX style headers")
cmd.PersistentFlags().BoolVar(&config.Settings.Default, "default", true, "show Default column or section")
cmd.PersistentFlags().BoolVar(&config.Settings.Escape, "escape", true, "escape special characters")
cmd.PersistentFlags().BoolVar(&config.Settings.HTML, "html", true, "use HTML tags in genereted output")
Expand Down
1 change: 1 addition & 0 deletions docs/reference/markdown-document.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ terraform-docs markdown document [PATH] [flags]

```console
--anchor create anchor links (default true)
--atx-closed close ATX style headers
-c, --config string config file name (default ".terraform-docs.yml")
--default show Default column or section (default true)
--escape escape special characters (default true)
Expand Down
1 change: 1 addition & 0 deletions docs/reference/markdown-table.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ terraform-docs markdown table [PATH] [flags]

```console
--anchor create anchor links (default true)
--atx-closed close ATX style headers
-c, --config string config file name (default ".terraform-docs.yml")
--default show Default column or section (default true)
--escape escape special characters (default true)
Expand Down
1 change: 1 addition & 0 deletions docs/reference/markdown.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ terraform-docs markdown [PATH] [flags]

```console
--anchor create anchor links (default true)
--atx-closed close ATX style headers
--default show Default column or section (default true)
--escape escape special characters (default true)
-h, --help help for markdown
Expand Down
17 changes: 17 additions & 0 deletions format/markdown_document_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,23 @@ func TestMarkdownDocument(t *testing.T) {
}),
),
},
"WithAtxClosed": {
config: testutil.WithSections(
testutil.WithHTML(),
testutil.With(func(c *print.Config) {
c.Settings.AtxClosed = true
}),
),
},
"EmptyWithAtxClosed": {
config: testutil.WithDefaultSections(
testutil.WithHTML(),
testutil.With(func(c *print.Config) {
c.ModuleRoot = "empty"
c.Settings.AtxClosed = true
}),
),
},

// Only section
"OnlyDataSources": {
Expand Down
17 changes: 17 additions & 0 deletions format/markdown_table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,23 @@ func TestMarkdownTable(t *testing.T) {
}),
),
},
"WithAtxClosed": {
config: testutil.WithSections(
testutil.WithHTML(),
testutil.With(func(c *print.Config) {
c.Settings.AtxClosed = true
}),
),
},
"EmptyWithAtxClosed": {
config: testutil.WithDefaultSections(
testutil.WithHTML(),
testutil.With(func(c *print.Config) {
c.ModuleRoot = "empty"
c.Settings.AtxClosed = true
}),
),
},

// Only section
"OnlyDataSources": {
Expand Down
18 changes: 9 additions & 9 deletions format/templates/markdown_document_inputs.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
{{- if .Config.Settings.Required -}}
{{- if not .Module.RequiredInputs -}}
{{- if not .Config.Settings.HideEmpty -}}
{{- indent 0 "#" }} Required Inputs
{{- indent 0 "#" }} Required Inputs{{ if .Config.Settings.AtxClosed }} {{ indent 0 "#" }}{{ end }}

No required inputs.
{{ end }}
{{ else }}
{{- indent 0 "#" }} Required Inputs
{{- indent 0 "#" }} Required Inputs{{ if .Config.Settings.AtxClosed }} {{ indent 0 "#" }}{{ end }}

The following input variables are required:
{{- range .Module.RequiredInputs }}
{{ printf "\n" }}
{{ indent 1 "#" }} {{ anchorNameMarkdown "input" .Name }}
{{ indent 1 "#" }} {{ anchorNameMarkdown "input" .Name }}{{ if $.Config.Settings.AtxClosed }} {{ indent 1 "#" }}{{ end }}

Description: {{ tostring .Description | sanitizeDoc }}

Expand All @@ -29,17 +29,17 @@
{{- end }}
{{- if not .Module.OptionalInputs -}}
{{- if not .Config.Settings.HideEmpty -}}
{{- indent 0 "#" }} Optional Inputs
{{- indent 0 "#" }} Optional Inputs{{ if .Config.Settings.AtxClosed }} {{ indent 0 "#" }}{{ end }}

No optional inputs.
{{ end }}
{{ else }}
{{- indent 0 "#" }} Optional Inputs
{{- indent 0 "#" }} Optional Inputs{{ if .Config.Settings.AtxClosed }} {{ indent 0 "#" }}{{ end }}

The following input variables are optional (have default values):
{{- range .Module.OptionalInputs }}
{{ printf "\n" }}
{{ indent 1 "#" }} {{ anchorNameMarkdown "input" .Name }}
{{ indent 1 "#" }} {{ anchorNameMarkdown "input" .Name }}{{ if $.Config.Settings.AtxClosed }} {{ indent 1 "#" }}{{ end }}

Description: {{ tostring .Description | sanitizeDoc }}

Expand All @@ -57,17 +57,17 @@
{{ else -}}
{{- if not .Module.Inputs -}}
{{- if not .Config.Settings.HideEmpty -}}
{{- indent 0 "#" }} Inputs
{{- indent 0 "#" }} Inputs{{ if .Config.Settings.AtxClosed }} {{ indent 0 "#" }}{{ end }}

No inputs.
{{ end }}
{{ else }}
{{- indent 0 "#" }} Inputs
{{- indent 0 "#" }} Inputs{{ if .Config.Settings.AtxClosed }} {{ indent 0 "#" }}{{ end }}

The following input variables are supported:
{{- range .Module.Inputs }}
{{ printf "\n" }}
{{ indent 1 "#" }} {{ anchorNameMarkdown "input" .Name }}
{{ indent 1 "#" }} {{ anchorNameMarkdown "input" .Name }}{{ if $.Config.Settings.AtxClosed }} {{ indent 1 "#" }}{{ end }}

Description: {{ tostring .Description | sanitizeDoc }}

Expand Down
6 changes: 3 additions & 3 deletions format/templates/markdown_document_modules.tmpl
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
{{- if .Config.Sections.ModuleCalls -}}
{{- if not .Module.ModuleCalls -}}
{{- if not .Config.Settings.HideEmpty -}}
{{- indent 0 "#" }} Modules
{{- indent 0 "#" }} Modules{{ if .Config.Settings.AtxClosed }} {{ indent 0 "#" }}{{ end }}

No modules.
{{ end }}
{{ else }}
{{- indent 0 "#" }} Modules
{{- indent 0 "#" }} Modules{{ if .Config.Settings.AtxClosed }} {{ indent 0 "#" }}{{ end }}

The following Modules are called:
{{- range .Module.ModuleCalls }}

{{ indent 1 "#" }} {{ anchorNameMarkdown "module" .Name }}
{{ indent 1 "#" }} {{ anchorNameMarkdown "module" .Name }}{{ if $.Config.Settings.AtxClosed }} {{ indent 1 "#" }}{{ end }}

Source: {{ .Source }}

Expand Down
6 changes: 3 additions & 3 deletions format/templates/markdown_document_outputs.tmpl
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
{{- if .Config.Sections.Outputs -}}
{{- if not .Module.Outputs -}}
{{- if not .Config.Settings.HideEmpty -}}
{{- indent 0 "#" }} Outputs
{{- indent 0 "#" }} Outputs{{ if .Config.Settings.AtxClosed }} {{ indent 0 "#" }}{{ end }}

No outputs.
{{ end }}
{{ else }}
{{- indent 0 "#" }} Outputs
{{- indent 0 "#" }} Outputs{{ if .Config.Settings.AtxClosed }} {{ indent 0 "#" }}{{ end }}

The following outputs are exported:
{{- range .Module.Outputs }}

{{ indent 1 "#" }} {{ anchorNameMarkdown "output" .Name }}
{{ indent 1 "#" }} {{ anchorNameMarkdown "output" .Name }}{{ if $.Config.Settings.AtxClosed }} {{ indent 1 "#" }}{{ end }}

Description: {{ tostring .Description | sanitizeDoc }}

Expand Down
4 changes: 2 additions & 2 deletions format/templates/markdown_document_providers.tmpl
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{{- if .Config.Sections.Providers -}}
{{- if not .Module.Providers -}}
{{- if not .Config.Settings.HideEmpty -}}
{{- indent 0 "#" }} Providers
{{- indent 0 "#" }} Providers{{ if .Config.Settings.AtxClosed }} {{ indent 0 "#" }}{{ end }}

No providers.
{{ end }}
{{ else }}
{{- indent 0 "#" }} Providers
{{- indent 0 "#" }} Providers{{ if .Config.Settings.AtxClosed }} {{ indent 0 "#" }}{{ end }}

The following providers are used by this module:
{{- range .Module.Providers }}
Expand Down
4 changes: 2 additions & 2 deletions format/templates/markdown_document_requirements.tmpl
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{{- if .Config.Sections.Requirements -}}
{{- if not .Module.Requirements -}}
{{- if not .Config.Settings.HideEmpty -}}
{{- indent 0 "#" }} Requirements
{{- indent 0 "#" }} Requirements{{ if .Config.Settings.AtxClosed }} {{ indent 0 "#" }}{{ end }}

No requirements.
{{ end }}
{{ else }}
{{- indent 0 "#" }} Requirements
{{- indent 0 "#" }} Requirements{{ if .Config.Settings.AtxClosed }} {{ indent 0 "#" }}{{ end }}

The following requirements are needed by this module:
{{- range .Module.Requirements }}
Expand Down
4 changes: 2 additions & 2 deletions format/templates/markdown_document_resources.tmpl
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{{- if or .Config.Sections.Resources .Config.Sections.DataSources -}}
{{- if not .Module.Resources -}}
{{- if not .Config.Settings.HideEmpty -}}
{{- indent 0 "#" }} Resources
{{- indent 0 "#" }} Resources{{ if .Config.Settings.AtxClosed }} {{ indent 0 "#" }}{{ end }}

No resources.
{{ end }}
{{ else }}
{{- indent 0 "#" }} Resources
{{- indent 0 "#" }} Resources{{ if .Config.Settings.AtxClosed }} {{ indent 0 "#" }}{{ end }}

The following resources are used by this module:
{{ range .Module.Resources }}
Expand Down
4 changes: 2 additions & 2 deletions format/templates/markdown_table_inputs.tmpl
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{{- if .Config.Sections.Inputs -}}
{{- if not .Module.Inputs -}}
{{- if not .Config.Settings.HideEmpty -}}
{{- indent 0 "#" }} Inputs
{{- indent 0 "#" }} Inputs{{ if .Config.Settings.AtxClosed }} {{ indent 0 "#" }}{{ end }}

No inputs.
{{- end }}
{{ else }}
{{- indent 0 "#" }} Inputs
{{- indent 0 "#" }} Inputs{{ if .Config.Settings.AtxClosed }} {{ indent 0 "#" }}{{ end }}

| Name | Description |
{{- if .Config.Settings.Type }} Type |{{ end }}
Expand Down
4 changes: 2 additions & 2 deletions format/templates/markdown_table_modules.tmpl
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{{- if .Config.Sections.ModuleCalls -}}
{{- if not .Module.ModuleCalls -}}
{{- if not .Config.Settings.HideEmpty -}}
{{- indent 0 "#" }} Modules
{{- indent 0 "#" }} Modules{{ if .Config.Settings.AtxClosed }} {{ indent 0 "#" }}{{ end }}

No modules.
{{ end }}
{{ else }}
{{- indent 0 "#" }} Modules
{{- indent 0 "#" }} Modules{{ if .Config.Settings.AtxClosed }} {{ indent 0 "#" }}{{ end }}

| Name | Source | Version |
|------|--------|---------|
Expand Down
4 changes: 2 additions & 2 deletions format/templates/markdown_table_outputs.tmpl
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{{- if .Config.Sections.Outputs -}}
{{- if not .Module.Outputs -}}
{{- if not .Config.Settings.HideEmpty -}}
{{- indent 0 "#" }} Outputs
{{- indent 0 "#" }} Outputs{{ if .Config.Settings.AtxClosed }} {{ indent 0 "#" }}{{ end }}

No outputs.
{{ end }}
{{ else }}
{{- indent 0 "#" }} Outputs
{{- indent 0 "#" }} Outputs{{ if .Config.Settings.AtxClosed }} {{ indent 0 "#" }}{{ end }}

| Name | Description |{{ if .Config.OutputValues.Enabled }} Value |{{ if $.Config.Settings.Sensitive }} Sensitive |{{ end }}{{ end }}
|------|-------------|{{ if .Config.OutputValues.Enabled }}-------|{{ if $.Config.Settings.Sensitive }}:---------:|{{ end }}{{ end }}
Expand Down
4 changes: 2 additions & 2 deletions format/templates/markdown_table_providers.tmpl
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{{- if .Config.Sections.Providers -}}
{{- if not .Module.Providers -}}
{{- if not .Config.Settings.HideEmpty -}}
{{- indent 0 "#" }} Providers
{{- indent 0 "#" }} Providers{{ if .Config.Settings.AtxClosed }} {{ indent 0 "#" }}{{ end }}

No providers.
{{ end }}
{{ else }}
{{- indent 0 "#" }} Providers
{{- indent 0 "#" }} Providers{{ if .Config.Settings.AtxClosed }} {{ indent 0 "#" }}{{ end }}

| Name | Version |
|------|---------|
Expand Down
4 changes: 2 additions & 2 deletions format/templates/markdown_table_requirements.tmpl
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{{- if .Config.Sections.Requirements -}}
{{- if not .Module.Requirements -}}
{{- if not .Config.Settings.HideEmpty -}}
{{- indent 0 "#" }} Requirements
{{- indent 0 "#" }} Requirements{{ if .Config.Settings.AtxClosed }} {{ indent 0 "#" }}{{ end }}

No requirements.
{{ end }}
{{ else }}
{{- indent 0 "#" }} Requirements
{{- indent 0 "#" }} Requirements{{ if .Config.Settings.AtxClosed }} {{ indent 0 "#" }}{{ end }}

| Name | Version |
|------|---------|
Expand Down
4 changes: 2 additions & 2 deletions format/templates/markdown_table_resources.tmpl
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{{- if or .Config.Sections.Resources .Config.Sections.DataSources -}}
{{- if not .Module.Resources -}}
{{- if not .Config.Settings.HideEmpty -}}
{{- indent 0 "#" }} Resources
{{- indent 0 "#" }} Resources{{ if .Config.Settings.AtxClosed }} {{ indent 0 "#" }}{{ end }}

No resources.
{{ end }}
{{ else }}
{{- indent 0 "#" }} Resources
{{- indent 0 "#" }} Resources{{ if .Config.Settings.AtxClosed }} {{ indent 0 "#" }}{{ end }}

| Name | Type |
|------|------|
Expand Down
23 changes: 23 additions & 0 deletions format/testdata/markdown/document-EmptyWithAtxClosed.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
## Requirements ##

No requirements.

## Providers ##

No providers.

## Modules ##

No modules.

## Resources ##

No resources.

## Inputs ##

No inputs.

## Outputs ##

No outputs.
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy