Skip to content

Broken partial indentation with nested sections #181

@jbortkiewicz

Description

@jbortkiewicz

Description:

When a partial contains multiple nested standalone sections,the indentation is rendered for each standalone section tag (opening and closing), causing an accumulated indentation preceding a next output.

Context:

I found this issue while trying to develop templates that produce "pretty" formatted code with openapi-generator. It is a very common use case (not only with openapi-generator), that partial contains several nested sections intended to implement complicated if-else conditions, thus this issue makes it impossible to generate a properly indented code.

To Reproduce

Affected versions: 1.16, master (00be427)
Failing test cases:

  - name: Partial Nested Section Indentation
    desc: Multiple nested standalone sections should not change indentation
    data: { content: "value" }
    template: |
      \
       {{>partial}}
      /
    partials:
      partial: |
        |
        {{#content}}
        {{#content}}
        {{{.}}}
        {{/content}}
        {{/content}}
        |
    expected: |
      \
       |
       value
       |
      /

  - name: Partial Indentation With Empty Nested Sections
    desc: Empty nested standalone sections should not change indentation
    data: { content: "value" }
    template: |
      \
       {{>partial}}
      /
    partials:
      partial: |
        |
        {{#content}}
        {{#missing}}
        {{.}}
        {{/missing}}
        {{/content}}
        |
    expected: |
      \
       |
       |
      /

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions