YtsFoldedScalars.yml (3962B)
1 --- %YAML:1.0 2 test: Single ending newline 3 brief: > 4 A pipe character, followed by an indented 5 block of text is treated as a literal 6 block, in which newlines are preserved 7 throughout the block, including the final 8 newline. 9 yaml: | 10 --- 11 this: | 12 Foo 13 Bar 14 php: | 15 array('this' => "Foo\nBar\n") 16 --- 17 test: The '+' indicator 18 brief: > 19 The '+' indicator says to keep newlines at the end of text 20 blocks. 21 yaml: | 22 normal: | 23 extra new lines not kept 24 25 preserving: |+ 26 extra new lines are kept 27 28 29 dummy: value 30 php: | 31 array( 32 'normal' => "extra new lines not kept\n", 33 'preserving' => "extra new lines are kept\n\n\n", 34 'dummy' => 'value' 35 ) 36 --- 37 test: Three trailing newlines in literals 38 brief: > 39 To give you more control over how space 40 is preserved in text blocks, YAML has 41 the keep '+' and chomp '-' indicators. 42 The keep indicator will preserve all 43 ending newlines, while the chomp indicator 44 will strip all ending newlines. 45 yaml: | 46 clipped: | 47 This has one newline. 48 49 50 51 same as "clipped" above: "This has one newline.\n" 52 53 stripped: |- 54 This has no newline. 55 56 57 58 same as "stripped" above: "This has no newline." 59 60 kept: |+ 61 This has four newlines. 62 63 64 65 same as "kept" above: "This has four newlines.\n\n\n\n" 66 php: | 67 array( 68 'clipped' => "This has one newline.\n", 69 'same as "clipped" above' => "This has one newline.\n", 70 'stripped' => 'This has no newline.', 71 'same as "stripped" above' => 'This has no newline.', 72 'kept' => "This has four newlines.\n\n\n\n", 73 'same as "kept" above' => "This has four newlines.\n\n\n\n" 74 ) 75 --- 76 test: Extra trailing newlines with spaces 77 todo: true 78 brief: > 79 Normally, only a single newline is kept 80 from the end of a literal block, unless the 81 keep '+' character is used in combination 82 with the pipe. The following example 83 will preserve all ending whitespace 84 since the last line of both literal blocks 85 contains spaces which extend past the indentation 86 level. 87 yaml: | 88 --- 89 this: | 90 Foo 91 92 93 kept: |+ 94 Foo 95 96 97 php: | 98 array('this' => "Foo\n\n \n", 99 'kept' => "Foo\n\n \n" ) 100 101 --- 102 test: Folded Block in a Sequence 103 brief: > 104 A greater-then character, followed by an indented 105 block of text is treated as a folded block, in 106 which lines of text separated by a single newline 107 are concatenated as a single line. 108 yaml: | 109 --- 110 - apple 111 - banana 112 - > 113 can't you see 114 the beauty of yaml? 115 hmm 116 - dog 117 php: | 118 array( 119 'apple', 120 'banana', 121 "can't you see the beauty of yaml? hmm\n", 122 'dog' 123 ) 124 --- 125 test: Folded Block as a Mapping Value 126 brief: > 127 Both literal and folded blocks can be 128 used in collections, as values in a 129 sequence or a mapping. 130 yaml: | 131 --- 132 quote: > 133 Mark McGwire's 134 year was crippled 135 by a knee injury. 136 source: espn 137 php: | 138 array( 139 'quote' => "Mark McGwire's year was crippled by a knee injury.\n", 140 'source' => 'espn' 141 ) 142 --- 143 test: Three trailing newlines in folded blocks 144 brief: > 145 The keep and chomp indicators can also 146 be applied to folded blocks. 147 yaml: | 148 clipped: > 149 This has one newline. 150 151 152 153 same as "clipped" above: "This has one newline.\n" 154 155 stripped: >- 156 This has no newline. 157 158 159 160 same as "stripped" above: "This has no newline." 161 162 kept: >+ 163 This has four newlines. 164 165 166 167 same as "kept" above: "This has four newlines.\n\n\n\n" 168 php: | 169 array( 170 'clipped' => "This has one newline.\n", 171 'same as "clipped" above' => "This has one newline.\n", 172 'stripped' => 'This has no newline.', 173 'same as "stripped" above' => 'This has no newline.', 174 'kept' => "This has four newlines.\n\n\n\n", 175 'same as "kept" above' => "This has four newlines.\n\n\n\n" 176 )