你如何在 YAML 中阻止评论? [英] How do you do block comments in YAML?
问题描述
如何在 YAML 中注释一行代码?
How do I comment a block of lines in YAML?
推荐答案
YAML 支持内联注释,但不支持块注释.
YAML supports inline comments, but does not support block comments.
来自维基百科:
注释以数字符号 ( #
) 开头,可以从一行的任意位置开始,一直持续到行尾
Comments begin with the number sign (
#
), can start anywhere on a line, and continue until the end of the line
与 JSON 的比较,同样来自 维基百科:
A comparison with JSON, also from Wikipedia:
语法差异是微妙的,在实践中很少出现:JSON 允许像 UTF-32 这样的扩展字符集,YAML 需要在逗号、等号和冒号等分隔符后有一个空格,而 JSON 则不需要,还有一些 JSON 扩展的非标准实现包含 Javascript 的 /* ... */
注释的语法.处理此类边缘情况可能需要在解析为内联 YAML 之前对 JSON 进行轻度预处理.
The syntax differences are subtle and seldom arise in practice: JSON allows extended charactersets like UTF-32, YAML requires a space after separators like comma, equals, and colon while JSON does not, and some non-standard implementations of JSON extend the grammar to include Javascript's
/* ... */
comments. Handling such edge cases may require light pre-processing of the JSON before parsing as in-line YAML.
# If you want to write
# a block-commented Haiku
# you'll need three pound signs
这篇关于你如何在 YAML 中阻止评论?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!