如何在yaml中的多行字符串中转义哈希(#)字符?

Ale*_*eta 5 markdown yaml

我需要做以下事情:

description: |-
    #This is not a comment#
    Some more text.
Run Code Online (Sandbox Code Playgroud)

但是当然第一行被解释为yaml解析器的注释.我不能在这里使用双引号,因为我需要这是多行的.

我能做些什么来实现这个目标?

谢谢.

Jak*_*ski 4

如果你确实正确缩进了它,它应该按照你的方式工作,看起来你确实这样做了。所以也许这是你的解析器中的一个错误。

它似乎适用于 SnakeYAML - 将您的代码片段复制粘贴到http://instantyaml.appspot.com/返回:

%YAML 1.1
---
!!map {
    ? !!str "description"
    : !!str "#This is not a comment#\nSome more text.",
}
...
Run Code Online (Sandbox Code Playgroud)

这与您尝试不使用哈希值的相同示例本质上是相同的:

%YAML 1.1
---
!!map {
    ? !!str "description"
    : !!str "This is not a comment\nSome more text.",
}
...
Run Code Online (Sandbox Code Playgroud)