Merge pull request #544 from khos2ow/indented-code-block

Properly format indented code blocks
This commit is contained in:
Khosrow Moossavi
2021-07-28 19:56:14 -04:00
committed by GitHub
3 changed files with 30 additions and 1 deletions

View File

@@ -55,7 +55,16 @@ func sanitizeSection(s string, settings *print.Settings) string {
if !strings.HasSuffix(segment, "\n") {
lastbreak = "\n"
}
segment = fmt.Sprintf("```%s%s```", segment, lastbreak)
// Adjust indention and linebreak for indented codeblock
// https://github.com/terraform-docs/terraform-docs/issues/521
lastindent := ""
lines := strings.Split(segment, "\n")
if len(strings.TrimSpace(lines[len(lines)-1])) == 0 {
lastbreak = ""
}
segment = fmt.Sprintf("```%s%s%s```", segment, lastindent, lastbreak)
return segment
},
)

View File

@@ -28,6 +28,16 @@ module "foo_bar" {
}
```
1. Entry one with code
```json
{
"key": "value"
}
```
1. This line should not be broken
Here is some trailing text after code block,
followed by another line of text.

View File

@@ -28,6 +28,16 @@ module "foo_bar" {
}
```
1. Entry one with code
```json
{
"key": "value"
}
```
1. This line should not be broken
Here is some trailing text after code block,
followed by another line of text.