YtsFoldedScalars.yml 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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. preserving: |+
  25. extra new lines are kept
  26. dummy: value
  27. php: |
  28. array(
  29. 'normal' => "extra new lines not kept\n",
  30. 'preserving' => "extra new lines are kept\n\n\n",
  31. 'dummy' => 'value'
  32. )
  33. ---
  34. test: Three trailing newlines in literals
  35. brief: >
  36. To give you more control over how space
  37. is preserved in text blocks, YAML has
  38. the keep '+' and chomp '-' indicators.
  39. The keep indicator will preserve all
  40. ending newlines, while the chomp indicator
  41. will strip all ending newlines.
  42. yaml: |
  43. clipped: |
  44. This has one newline.
  45. same as "clipped" above: "This has one newline.\n"
  46. stripped: |-
  47. This has no newline.
  48. same as "stripped" above: "This has no newline."
  49. kept: |+
  50. This has four newlines.
  51. same as "kept" above: "This has four newlines.\n\n\n\n"
  52. php: |
  53. array(
  54. 'clipped' => "This has one newline.\n",
  55. 'same as "clipped" above' => "This has one newline.\n",
  56. 'stripped' => 'This has no newline.',
  57. 'same as "stripped" above' => 'This has no newline.',
  58. 'kept' => "This has four newlines.\n\n\n\n",
  59. 'same as "kept" above' => "This has four newlines.\n\n\n\n"
  60. )
  61. ---
  62. test: Extra trailing newlines with spaces
  63. todo: true
  64. brief: >
  65. Normally, only a single newline is kept
  66. from the end of a literal block, unless the
  67. keep '+' character is used in combination
  68. with the pipe. The following example
  69. will preserve all ending whitespace
  70. since the last line of both literal blocks
  71. contains spaces which extend past the indentation
  72. level.
  73. yaml: |
  74. ---
  75. this: |
  76. Foo
  77. kept: |+
  78. Foo
  79. php: |
  80. array('this' => "Foo\n\n \n",
  81. 'kept' => "Foo\n\n \n" )
  82. ---
  83. test: Folded Block in a Sequence
  84. brief: >
  85. A greater-then character, followed by an indented
  86. block of text is treated as a folded block, in
  87. which lines of text separated by a single newline
  88. are concatenated as a single line.
  89. yaml: |
  90. ---
  91. - apple
  92. - banana
  93. - >
  94. can't you see
  95. the beauty of yaml?
  96. hmm
  97. - dog
  98. php: |
  99. array(
  100. 'apple',
  101. 'banana',
  102. "can't you see the beauty of yaml? hmm\n",
  103. 'dog'
  104. )
  105. ---
  106. test: Folded Block as a Mapping Value
  107. brief: >
  108. Both literal and folded blocks can be
  109. used in collections, as values in a
  110. sequence or a mapping.
  111. yaml: |
  112. ---
  113. quote: >
  114. Mark McGwire's
  115. year was crippled
  116. by a knee injury.
  117. source: espn
  118. php: |
  119. array(
  120. 'quote' => "Mark McGwire's year was crippled by a knee injury.\n",
  121. 'source' => 'espn'
  122. )
  123. ---
  124. test: Three trailing newlines in folded blocks
  125. brief: >
  126. The keep and chomp indicators can also
  127. be applied to folded blocks.
  128. yaml: |
  129. clipped: >
  130. This has one newline.
  131. same as "clipped" above: "This has one newline.\n"
  132. stripped: >-
  133. This has no newline.
  134. same as "stripped" above: "This has no newline."
  135. kept: >+
  136. This has four newlines.
  137. same as "kept" above: "This has four newlines.\n\n\n\n"
  138. php: |
  139. array(
  140. 'clipped' => "This has one newline.\n",
  141. 'same as "clipped" above' => "This has one newline.\n",
  142. 'stripped' => 'This has no newline.',
  143. 'same as "stripped" above' => 'This has no newline.',
  144. 'kept' => "This has four newlines.\n\n\n\n",
  145. 'same as "kept" above' => "This has four newlines.\n\n\n\n"
  146. )