如果您运行此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
组?
答案 0 :(得分:1)
我最好的猜测是&锚具有非常高的优先级。我试过这个
- &first 'first': ['description', ['aliases'], ["Explanatory sentences ", "go here."]]
- *first
而不是:
- &first {'first': ['description', ['aliases'], ["Explanatory sentences ", "go here."]]}
- *first
突然它的行为与second
组的行为方式相同。因此,除非您在更大的节点中明确包含'first'
,否则&first
锚点只会附加到'first'
字符串,而不是其他内容。