Skip to content

feat: Support YAML literal blocks for multiline strings#851

Open
ivov wants to merge 1 commit intomitsuhiko:masterfrom
ivov:yaml-literal-blocks-for-multiline-strings
Open

feat: Support YAML literal blocks for multiline strings#851
ivov wants to merge 1 commit intomitsuhiko:masterfrom
ivov:yaml-literal-blocks-for-multiline-strings

Conversation

@ivov
Copy link
Copy Markdown

@ivov ivov commented Dec 30, 2025

Thanks for the project!

This PR adds opt-in support for YAML literal blocks for multiline strings in snapshot metadata fields like description and expression. Trailing newlines are preserved via chomping indicators (|-, |, |+).

Set INSTA_YAML_BLOCK_STYLE=1 to enable.

Before:

expression: "fn add(a: i32, b: i32) -> i32 {\n    a + b\n}"

After:

expression: |-
  fn add(a: i32, b: i32) -> i32 {
      a + b
  }

I noticed the YAML lib is vendored and assumed extending it was acceptable - please let me know if you'd prefer a different approach.

Closes #782

@max-sixty
Copy link
Copy Markdown
Collaborator

thanks for the contribution

what's the standard for frontmatter — are these allowed?

I agree this makes it more readable. OTOH it adds another option + introduces backward-compat issues, so need to weigh those...

@ivov
Copy link
Copy Markdown
Author

ivov commented Dec 30, 2025

Thanks for the quick reply :)

what's the standard for frontmatter — are these allowed?

Yes! Literal blocks are standard YAML so any compliant parser handles them, and frontmatter is YAML between --- markers, not a separate spec.

I agree this makes it more readable. OTOH it adds another option + introduces backward-compat issues, so need to weigh those...

Added as opt-in so users control the switch. Older insta versions support this because the parser already supports literal blocks - this PR only extends the emitter. But indeed it's a new option to maintain.

@max-sixty
Copy link
Copy Markdown
Collaborator

yes, another option would be "min-version", which we've thought about a bit before... I think the versioning is basically the only reason to have the config here; so in that case we could just adopt the "min-version" config. Or push this to #456

let me leave this open for a bit to see if others have thoughts (including @mitsuhiko )

thank you again

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

YAML block formatting for expression string

2 participants