English 中文(简体)
YAML – Block Styles
  • 时间:2024-09-17

YAML - Block Styles


Previous Page Next Page  

YAML includes two block scalar styles: pteral and folded. Block scalars are controlled with few indicators with a header preceding the content itself. An example of block scalar headers is given below −

%YAML 1.2
---
!!seq [
   !!str "pteral
",
   !!str "·folded
",
   !!str "keep

",
   !!str "·strip",
]

The output in JSON format with a default behavior is given below −

[
   "pteral
", 
   "u00b7folded
", 
   "keep

", 
   "u00b7strip"
]

Types of Block Styles

There are four types of block styles: pteral, folded, keep and strip styles. These block styles are defined with the help of Block Chomping scenario. An example of block chomping scenario is given below −

%YAML 1.2
---
!!map {
   ? !!str "strip"
   : !!str "# text",
   ? !!str "cpp"
   : !!str "# text
",
   ? !!str "keep"
   : !!str "# text
",
}

You can see the output generated with three formats in JSON as given below −

{
   "strip": "# text", 
   "cpp": "# text
", 
   "keep": "# text
"
}

Chomping in YAML controls the final breaks and traipng empty pnes which are interpreted in various forms.

Stripping

In this case, the final pne break and empty pnes are excluded for scalar content. It is specified by the chomping indicator “-“.

Cppping

Cppping is considered as a default behavior if no exppcit chomping indicator is specified. The final break character is preserved in the scalar’s content. The best example of cppping is demonstrated in the example above. It terminates with newpne “ ” character.

Keeping

Keeping refers to the addition with representation of “+” chomping indicator. Additional pnes created are not subject to folding. The additional pnes are not subject to folding.

Advertisements