2

如果你运行这个 YAML 1.1

- &first {'first': ['description', ['aliases'], ["Explanatory sentences ", "go here."]]}
- *first
- &second 'second':
    - 'description'
    - ['aliases']
    -
        - "Explanatory sentences "
        - "go here."
- *second

通过YAMLlint,你得到这个:

--- 
- 
  first: 
    - description
    - 
      - aliases
    - 
      - "Explanatory sentences "
      - "go here."
- 
  first: 
    - description
    - 
      - aliases
    - 
      - "Explanatory sentences "
      - "go here."
- 
  second: 
    - description
    - 
      - aliases
    - 
      - "Explanatory sentences "
      - "go here."
- second

请注意,该first组重复两次,而该second组仅完整显示一次,仅显示重复块应位于的名称。first组和组的second数据完全相同——唯一的区别是布局。为什么别名不适用于second组?

4

1 回答 1

1

我最好的猜测是 &anchor 具有非常高的优先级。我试过这个

- &first 'first': ['description', ['aliases'], ["Explanatory sentences ", "go here."]]
- *first

而不是这样:

- &first {'first': ['description', ['aliases'], ["Explanatory sentences ", "go here."]]}
- *first

突然间,它的行为方式与该second组相同。'first'因此,除非您在更大的节点中明确包含 ,否则锚点似乎&first只附加到'first'字符串而不附加任何其他内容。

于 2013-01-26T15:40:43.303 回答