In YAML, the |
and >
characters are used to denote different styles of multi-line strings. Here's a brief explanation of each:
The |
character is used to preserve the exact formatting of the multi-line string, including line breaks and leading spaces. It's useful when you want to maintain the formatting of the text exactly as it is.
Example:
example_literal: |
This is a literal block scalar.
It preserves line breaks and
leading spaces.
This will result in:
This is a literal block scalar.
It preserves line breaks and
leading spaces.
The >
character is used to fold the multi-line string, which means line breaks are converted to spaces. This is useful for long paragraphs of text where you want to preserve the paragraph structure but don't need the exact line breaks.
Example:
example_folded: >
This is a folded block scalar.
It folds line breaks into spaces,
making the text more compact.
This will result in:
This is a folded block scalar. It folds line breaks into spaces, making the text more compact.
- Literal Block Scalar (
|
): Preserves line breaks and leading spaces. - Folded Block Scalar (
>
): Converts line breaks to spaces, making the text more compact.
Choose |
when you need to preserve the exact formatting, and >
when you prefer a more compact representation that merges lines into a single paragraph.