Skip to content

Add separate whitespace controls for block scalar text bodies #313

@axellpadilla

Description

@axellpadilla

Description

yamlfix already provides document-level whitespace controls such as whitelines, section_whitelines, and comments_whitelines, but it does not appear to provide equivalent control for whitespace inside YAML block scalars.

This is noticeable in Kubernetes manifests and other YAML files that embed scripts or configuration text in |, |-, >, or >- blocks. In those cases, the content inside the block scalar is intentional text, and its spacing may need to be treated differently from the surrounding YAML structure.

For example:

data:
  refresh.py: |-
    def first():
        pass


    def second():
        pass

I want yamlfix to be able to control blank lines inside the block scalar body independently from the outer YAML document formatting.

Possible Solution

Add a block-scalar-specific whitespace option, in the same spirit as the existing whitespace controls, so users can tune whitespace handling inside block scalar bodies without affecting normal YAML mappings and sequences.

For example, an option such as block_scalar_whitelines could:

preserve blank lines inside block scalars
collapse repeated blank lines inside block scalars
trim leading or trailing blank lines inside block scalar bodies
The key point is that this should apply only to block scalar content and leave the existing document-level behavior unchanged.

Additional context

This comes up frequently in Kubernetes YAML, especially in ConfigMaps, values.yaml files, and other manifests that embed scripts or multiline text.

Today, yamlfix can normalize whitespace around YAML structure, but block scalar text is still handled as part of the surrounding document formatting. That can create noisy diffs when embedded scripts use blank lines for readability.

Related Issue

None found

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