Search code examples
ruby-on-railsyaml

new line "\n" in yaml file


I'd like to do this

test: >
  This is a long string
  \n\n\n
  with new lines

But it prints out the "\n" instead of making new lines.

I know it's possible to do

test: "This is a long string
      \n\n\n
      with new lines"

But i'd rather not add quotes everywhere if possible. Thanks for the help!

EDIT: I'd rather not use empty lines. In other words, i'd like to use \n to show empty lines to make my yml file more readable.


Solution

  • try this

    test: |+
      This is a long string
    
    
      with new lines
    

    | after the key helps in beginning of multiline text indented and maintain the indentation for the long string.