mirror of
https://github.com/terraform-docs/terraform-docs.git
synced 2026-03-27 12:58:35 +07:00
Merge pull request #544 from khos2ow/indented-code-block
Properly format indented code blocks
This commit is contained in:
@@ -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
|
||||
},
|
||||
)
|
||||
|
||||
@@ -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.
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user