【问题标题】:YAML comments in multi-line strings多行字符串中的 YAML 注释
【发布时间】:2014-01-20 08:14:37
【问题描述】:

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

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

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

【问题讨论】:

    标签: yaml


    【解决方案1】:

    没有。根据YAML 1.2 spec“评论不得出现在标量内”。这正是这里的情况。 YAML 中无法转义 octothorpe 符号 (#),因此在多行字符串中,无法区分注释与原始字符串值。

    但是,您可以在集合中交错 cmets。例如,如果你真的需要,你可以把你的字符串分解成一个字符串序列,每行一个:

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

    应该可以...

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-02-04
      • 1970-01-01
      • 2011-10-18
      • 1970-01-01
      • 1970-01-01
      • 2010-09-07
      • 1970-01-01
      • 2019-06-10
      相关资源
      最近更新 更多