【问题标题】:new line "\n" in yaml fileyaml 文件中的新行“\n”
【发布时间】:2012-07-19 22:36:11
【问题描述】:

我想这样做

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

但它会打印出“\n”而不是换行。

我知道这是可能的

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

但如果可能的话,我宁愿不要在任何地方添加引号。 感谢您的帮助!

编辑:我宁愿不使用空行。换句话说,我想使用 \n 来显示空行以使我的 yml 文件更具可读性。

【问题讨论】:

标签: ruby-on-rails yaml


【解决方案1】:

要在 yaml 中打印新行,您可以执行以下代码 我正在使用像这样的 degu 模块 msg func

debug:
   msg:
     - 'hello'
     - 'name'

【讨论】:

    【解决方案2】:

    你可以这样做:

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

    【讨论】:

      【解决方案3】:

      试试这个

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

      |后键有助于缩进多行文本的开头并保持长字符串的缩进。

      【讨论】:

      猜你喜欢
      • 2020-01-22
      • 2018-11-27
      • 2022-06-12
      • 1970-01-01
      • 2011-12-13
      • 2023-02-11
      • 2019-06-06
      • 1970-01-01
      • 2012-11-10
      相关资源
      最近更新 更多