如何在Yaml中的多行字符串中转义井号(#)字符? [英] How to escape hash (#) character in a multi-line string in yaml?

查看:490
本文介绍了如何在Yaml中的多行字符串中转义井号(#)字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要执行以下操作:

description: |-
    #This is not a comment#
    Some more text.

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

But of course the first line is interpreted as a comment by the yaml parser. I cannot use double quotes here since I need this to be multiline.

我该怎么做?

谢谢.

推荐答案

如果您确实正确地缩进了它的模样,它应该以您拥有它的方式工作.因此,也许这是解析器中的错误.

It should work the way you have it if you really have it indented properly which it seems that you do. So maybe it is a bug in your parser.

它似乎可以与SnakeYAML一起使用-将您的代码段复制粘贴到 http://instantyaml.appspot.com/返回:

It seems to work with SnakeYAML - copy pasting your snippet to http://instantyaml.appspot.com/ returns:

%YAML 1.1
---
!!map {
    ? !!str "description"
    : !!str "#This is not a comment#\nSome more text.",
}
...

与尝试不带散列的相同示例时的本质相同:

Which is essentially the same as when you try the same example without hashes:

%YAML 1.1
---
!!map {
    ? !!str "description"
    : !!str "This is not a comment\nSome more text.",
}
...

这篇关于如何在Yaml中的多行字符串中转义井号(#)字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆