2

I have a multi-line string whose first line is indented, but subsequent lines are not. How do I represent this in YAML?

      12    24
30    60    53
36    66    59

YAML sees the de-dentation and considers it the end of the string.

Here's one way I could do it. But it would be nice if I could more easily cut-and-paste the values without modifying the string so much.

"      12    24\n\
\30    60    53\n\
\36    66    59"
codeforester
  • 39,467
  • 16
  • 112
  • 140
Mike M. Lin
  • 9,992
  • 12
  • 53
  • 62
  • See also a complete comparison over multi-lines strings in YAML at the following answer: http://stackoverflow.com/a/21699210/248390 – bufh Oct 25 '16 at 14:36

1 Answers1

4

You can do this somewhat more easy by using the the literal block style combined with an appropriate block header doing explicit block indentation indication (instead of automatic) and block strip chomping:

|1-
       12    24
 30    60    53
 36    66    59

Unfortunately there is no way to reduce the indentation further to 0, as there would be no indication as to where the block would end and a next item started. It would probably have been better if the specification had allowed zero or negative indentation for literal blocks while requiring number of lines to be specified ( |0:3- ), but that is not in the specs.

Anthon
  • 69,918
  • 32
  • 186
  • 246