mirror of
https://github.com/terraform-docs/terraform-docs.git
synced 2026-03-27 12:58:35 +07:00
Properly format indented code blocks
If a code block (surrounded by triple backticks) are indented, in other words the code block is placed inside ordered or unordered list, the closing backticks of codeblock should honor the original indentation properly. Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com>
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