多行字符串中的 YAML 注释 [英] YAML comments in multi-line strings

查看:74
本文介绍了多行字符串中的 YAML 注释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

YAML 是否支持多行字符串中的注释?

Does YAML support comments in multi-line strings?

我正在尝试做这样的事情,但验证器抛出错误:

I'm trying to do things like this, but the validator is throwing errors:

key:
  #comment
  value
  #comment
  value
  value     #comments here don't work either

推荐答案

没有.根据 YAML 1.2 规范注释不得出现在标量中".这正是这里的情况.YAML 中无法转义八字符号 (#),因此在多行字符串中无法从原始字符串值中消除注释的歧义.

No. Per the YAML 1.2 spec "Comments must not appear inside scalars". Which is exactly the case here. There's no way in YAML to escape the octothorpe symbol (#) so within a multi-line string there's no way to disambiguate the comment from the raw string value.

然而,您可以在集合中插入评论.例如,如果您确实需要,您可以将您的字符串分解为每行一个的字符串序列:

You can however interleave comments within a collection. For example, if you really needed to, you could break your string into a sequence of strings one per line:

key: #comment
  - value line 1
  #comment
  - value line 2
  #comment
  - value line 3

应该可以...

这篇关于多行字符串中的 YAML 注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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