Respecte l’indentation (uniquement via les espaces)
- – avec [ pour les listes
- : avec { pour les mappings (enregistrements / tableau associatifs)
Pour le multi-ligne c’est un peu compliqué (_ veut dire espace):
- | et > démarre à la ligne suivante, garde les espaces à la fin
- | considère les sauts de ligne comme des sauts de ligne et pas des espaces
- _ et ‘ et « sur la même ligne, élimine les espaces à la fin
- « échappe les \n et \ et «
- _ si la chaîne ne contient pas # ou :
| Scalars |
# scalar = value a: 1 a: 1.234 b: 'abc' b: "abc" b: abc c: false # boolean type d: 2015-04-05 # date type # Enforcing strings b: !str 2015-04-05 |
| Sequences |
# sequence array: - 132 - 2.434 - 'abc' # sqeuence of sequences my_array: - [1, 2, 3] - [4, 5, 6] |
| Hashes |
# Nest hash
my_hash:
subkey:
subsubkey1: 5
subsubkey2: 6
another:
somethingelse: 'Important!'
# Hash of hashes
my_hash: {nr1: 5, nr2: 6}
|
| Newlines |
# block notation (newlines become spaces) content: Arbitrary free text over multiple lines stopping after indentation changes... # literal style (newlines are preserved) content: | Arbitrary free text over "multiple lines" stopping after indentation changes... # + indicator (keep extra newlines after block) content: |+ Arbitrary free text with two newlines after # - indicator (remove extra newlines after block) content: |- Arbitrary free text without newlines after it # folded style (plié newlines are preserved) content: > Arbitrary free text over "multiple lines" stopping after indentation changes... |
| Multiple Documents |
--- content: doc1 --- content: doc2 |
| Reference Content |
--- values: - &ref Something to reuse - *ref # Reused content |
| Merging Keys |
default_settings:
install:
dir: /usr/local
owner: root
config:
enabled: false
# Derive settings for 'my_app' from default and change install::owner
my_app_settings:
<<: *default_settings
install:
owner: my_user
|
| Complex Mapping |
--- ? - key : - value # Note: key and value can be multiple, complex structures |
| Tags |
%TAG !personne! tag:foo.org,2004:bar
---
- !personne
nom: Simpson
prenom: Omer
explicit_string: !!str 0.5
python_complex_number: !!python/complex 1+2j
|
Mémo pour les sautes de ligne
| > | | | _ | « | ‘ | >- | |
| Trailing spaces | Kept | Kept | Kept | |||
| Single newline => | _ | \n | _ | _ | _ | _ |
| Double newline => | \n | \n\n | \n | \n | \n | \n |
| In-line newlines | No | No | No | \n | No | No |
| Appended* | \n | \n | \n | |||
| Single quote | ‘ | ‘ | ‘ | ‘ | » | ‘ |
| Double quote | « | « | « | \ » | « | « |
| Backslash | \ | \ | \ | \\ | \ | \ |
| » # », « : « | Ok | Ok | No | Ok | Ok | Ok |
| Can start on same line as key | No | No | Yes | Yes | Yes | No |
- http://symfony.com/legacy/doc/reference/1_3/fr/02-yaml
- http://www.yaml.org/refcard.html
- http://lzone.de/cheat-sheet/YAML
- https://fr.wikipedia.org/wiki/YAML
- http://sweetohm.net/article/introduction-yaml.html
- http://stackoverflow.com/questions/3790454/in-yaml-how-do-i-break-a-string-over-multiple-lines
- http://learnxinyminutes.com/docs/yaml/