Jay Taylor's notes
back to listing indexIn YAML, how do I break a string over multiple lines?
[web search]
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:
and I'd like to have this (or something to this effect):
I'd like to use quotes as above, so I don't need to escape anything within the string. |
|||
http://symfony.com/doc/current/components/yaml/yaml_format.html |
|||||||||||||||||||||||||||||||||
|
There are Block scalar styles (
|
|
|||||
|
Perhaps add the line-folding style (>-) as well: yaml.org/spec/1.2/spec.html#id2779048
– equaeghe
Oct 7 '15 at 10:19
|
||||
|
Holy crap, thanks. YAML is nuts. 6 different formats for multi-line strings.
– Steve Bennett
Oct 7 '15 at 23:17
|
||||
|
this should be the accepted answer. MUCH more useful than only describing
> as in the current accepted answer.
– m_x
Oct 29 '15 at 14:56
|
||||
|
>- is a combination of 8.1 "Block Scalar Styles" and 8.1.1.2 "Block Chomping Indicator". In this case, > (Block Scalar Style = Literal) and - (Block Chomping Indicator = Strip). Other combinations are possible, such as |- , >+ , and |+ (+ is Keep, which keeps all trailing empty lines instead of just one). So... that brings us to 9? :-)
– Brandon Bonds
Dec 2 '15 at 16:48
|
||||
To preserve newlines use
is translated to "This is a very long sentence\n that spans several lines in the YAML\n but which will be rendered as a string\n with newlines preserved." |
|||||||||||||||||||||||||||||||||
|
You might not believe it, but YAML can do multi-line keys too:
|
|||||||||
|
In case you're using yml and Twig for translations in Symfony, and want to use multi-line translations in Javascript, a carriage return is added right after the translation. So even the following code:
Which has the following yml translation:
Will still result into the following code in html:
So, the minus sign in Twig does not solve this. The solution is to add this minus sign after the greater than sign in yml:
Will have the proper result, multi line translation on one line in Twig:
|
|||||||||
|
Your Answer
Not the answer you're looking for? Browse other questions tagged yaml or ask your own question.
asked |
5 years ago |
viewed |
80907 times |
active |
Linked
Related
Hot Network Questions
- Does the use of macro in LaTeX slow down the compilation process?
- Write plural of/to the following words
- How were the English and French armies invited into Belgium in 1914?
- Why did mv delete a file with mv id_rsa *.old?
- High voltage three phase transmission lines
- Did Marty wipe his children from existence?
- Is if (condition) try {...} legal in C++?
- Is this heavy blue-green growth on my tree trunk and branches a form of lichen?
- Which mechanisms prevent biased very negative reviews?
- Why is second the duration of exactly 9192631770 periods of radiations?
- Seeking texts of all prayers associated with the clock change
- I'm a White Hat and I develop my own viruses. Should I report it when almost all scanners say the executable is safe?
- Happy Rounded Pi Day
- Why Proton launcher for ExoMars, and not Ariane?
- Why aren’t remotely-controlled robots used in Star Trek?
- Give a specific case where calling a polynomial time function n times gives an exponential time algorithm
- Most succinct way to do a large switch statement in Java
- Elementary Lebesgue measure problem
- Where can square roots come from when they are not distances?
- Is it OK to go to postdocs for help?
- Minimum of a negative value
- What are the negative effects to the first author when adding coauthors?
- What is the difference between an amortized loan and a non-amortized loan?
- Is the Magic School Bus actually magic?
Technology | Life / Arts | Culture / Recreation | Science | Other | ||
---|---|---|---|---|---|---|