How do I break a string over multiple lines?

前端 未结 9 1167
有刺的猬
有刺的猬 2020-11-22 01:06

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

相关标签:
9条回答
  • 2020-11-22 01:27

    To concatenate long lines without whitespace, use double quotes and escape the newlines with backslashes:

    key: "Loremipsumdolorsitamet,consecteturadipiscingelit,seddoeiusmodtemp\
      orincididuntutlaboreetdoloremagnaaliqua."
    

    (Thanks @Tobia)

    0 讨论(0)
  • 2020-11-22 01:28

    You might not believe it, but YAML can do multi-line keys too:

    ?
     >
     multi
     line
     key
    :
      value
    
    0 讨论(0)
  • 2020-11-22 01:33

    Using yaml folded style. 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.
    

    In either case, each line break is replaced by a space.

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

    See https://yaml-multiline.info/

    0 讨论(0)
提交回复
热议问题