我需要做类似以下的事情:
description: |-
#This is not a comment#
Some more text.
但是yaml解析器会将第一行解释为注释。由于我需要多行输入,所以无法使用双引号。
我应该怎么做才能实现这个功能?
谢谢。
如果您的缩进正确,它应该按照您所期望的方式工作,看起来确实如此。因此,可能是解析器中的错误。
使用SnakeYAML似乎可以正常工作-将您的片段复制粘贴到http://instantyaml.appspot.com/返回:
%YAML 1.1
---
!!map {
? !!str "description"
: !!str "#This is not a comment#\nSome more text.",
}
...
这基本上与您在没有哈希的情况下尝试相同的示例时相同:
%YAML 1.1
---
!!map {
? !!str "description"
: !!str "This is not a comment\nSome more text.",
}
...