Friday, 21 April 2017

syntax - How do I break a string over multiple lines?



In YAML, I have a string that's very long. I want to keep this within the 80-column (or so) view of my editor, so I'd like to break the string. What's the syntax for this?



In other words, I have this:




Key: 'this is my very very very very very very long string'


and I'd like to have this (or something to this effect):



Key: 'this is my very very very ' +
'long string'



I'd like to use quotes as above, so I don't need to escape anything within the string.


Answer



Using yaml folded style, each line break is replaced by a space. The indention in each line will be ignored. A line break will be inserted at the end.



Key: >
This is a very long sentence
that spans several lines in the YAML
but which will be rendered as a string
with only a single carriage return appended to the end.



http://symfony.com/doc/current/components/yaml/yaml_format.html



You can use the "block chomping indicator" to eliminate the trailing line break, as follows:



Key: >-
This is a very long sentence
that spans several lines in the YAML
but which will be rendered as a string
with NO carriage returns.



There are other control tools available as well (for controlling indentation for example).



See https://yaml-multiline.info/


No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...