YAML 每个缩进多少个空格? [英] YAML How many spaces per indent?

查看:78
本文介绍了YAML 每个缩进多少个空格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我在 YAML 中每个缩进级别使用一个空格、两个或四个空格有什么区别吗?

Is there any difference if i use one space, two or four spaces per indent level in YAML?

对于每种结构类型的空格数是否有任何特定规则??

Are there any specific rules for space numbers per Structure type??

例如 4 个用于嵌套 ma​​ps 的空间,每个 列表项1 个空间等等??

For example 4 spaces for nesting maps , 1 space per list item etc??

我正在为弹性 beanstalk .ebextensions 编写 yaml 配置文件,我很难正确构建它.虽然我在 YAML Validator 中有有效的 yaml,但弹性 beantalk 似乎理解不同的结构.

I am writing a yaml configuration file for elastic beanstalk .ebextensions and i am having really hard time constructing this correctly. Although i have valid yaml in YAML Validator elastic beanstalk seems to understand a different structure.

推荐答案

在 YAML 中没有要求缩进任何具体数量的空格.也没有要求保持一致.例如,这是有效的 YAML:

There is no requirement in YAML to indent any concrete number of spaces. There is also no requirement to be consistent. So for example, this is valid YAML:

a:
 b:
     - c
     -  d
     - e
f:
    "ghi"

一些规则可能很有趣:

  • 流内容(即以 {[ 开头的所有内容)可以跨越多行,但必须缩进至少与周围当前块级别一样多的空格.
  • 块列表项可以(但不需要)与周围的块级具有相同的缩进,因为 - 被认为是缩进的一部分:
  • Flow content (i.e. everything that starts with { or [) can span multiple lines, but must be indented at least as many spaces as the surrounding current block level.
  • Block list items can (but don't need to) have the same indentation as the surrounding block level because - is considered part of the indentation:
a:    # top-level key
- b   # value of that key, which is a list
- c
c:    # next top-level key
 d    # non-list value which must be more indented

这篇关于YAML 每个缩进多少个空格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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