Reading — step 1 of 5
Read
~1 min readBlock Style
Multi-Line Strings
YAML's superpower vs JSON.
Literal (|): preserves newlines.
description: |
This is line 1.
This is line 2.
This is line 3.
Result: "This is line 1.\nThis is line 2.\nThis is line 3.\n".
Folded (>): joins lines with spaces; double-newlines stay.
text: >
These lines
fold into one.
This is a new paragraph.
Result: "These lines fold into one.\nThis is a new paragraph.\n".
Indentation: content indented MORE than the YAML key. Indent level becomes content's "zero".
key: |
Hello
World
Content: "Hello\n World\n" (note: 2 extra spaces preserved).
Chomping indicators (control trailing newlines):
- (none) — keep ONE trailing newline.
-— strip ALL trailing newlines.+— keep ALL trailing newlines.
strip: |-
text
another
clip: |
text
another
keep: |+
text
another
Trailing newlines:
strip:"text\nanother".clip:"text\nanother\n".keep:"text\nanother\n\n\n".
Used for:
- Embedded scripts in CI files:
script: |
echo "starting"
npm install
npm test
- Multi-line config (long descriptions, certificates).
Example certificates inside YAML:
ca_cert: |
-----BEGIN CERTIFICATE-----
MIIDXTCCAkWgAwIBAg...
-----END CERTIFICATE-----
Quoting alternative: double-quoted spans multiple lines (with explicit \n).
Discussion
Ask a question, share an insight, or help someone who’s stuck.
Sign in to post a comment or reply.
Loading…