syntax - 如何正确拥有多行 yaml 字符串?

标签 syntax yaml multiline

多行换行似乎对我不起作用:

就像是:

  intro: |
    We are happy that you are interested in
    and  
    more

and + more 需要在换行符上,但它失败了。
  intro: |
    | We are happy that you are interested in
    | and  
    | more

或者
  intro: |
    We are happy that you are interested in \n
    and  
    more <2 spaces >
    another one

都失败了。

如何在 yaml 文本块中正确使用多行?

我在 Rails 应用程序的 HAML View 中使用它,例如

= t("mailer.beta_welcome.intro")

但是没有以这种方式打印换行符,我是否需要使用 raw 或其他方式以不同的方式输出它?

最佳答案

你的第一个例子工作正常

文件名

intro: |
  We are happy that you are interested in
  and  
  more

文件名
require 'yaml'
puts YAML.load_file('foo.yml').inspect

输出
{"intro"=>"We are happy that you are interested in\nand  \nmore\n"}

关于syntax - 如何正确拥有多行 yaml 字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19959823/

相关文章:

c# - 将 null 转换为对象?

java - yml - 多个键映射到相同的值

ruby - 由于初始化程序 Yaml 文件,Rspec 测试未运行

string - 如何在 Powershell 控制台中分配多行字符串

text - CSS 多线渐变文本。 -webkit-背景剪辑

java - 为什么这些分号不会产生错误?

java - Java 的 lambda 语法的分割是什么?

batch-file - 批处理语法不正确?

yaml - 如何在 Build Yaml 中进行 dotnet 发布

c# - 用于大内容的 WPF 多行文本框