我在 yaml 脚本中有一个这样的变量:
variable: |
This is really long long line ---------------------------------------------------------------------------
And this line is not really long ---------
And i am just chilling here
我想通过 yamllint 验证我的所有脚本,所以我必须将第一行分成两部分而不更改其内容。 我该怎么做?
如果我尝试从字面上定义它,我会得到这样的结果:
variable: "\
This is really long long line ---------------------\
------------------------------------------------------\n
And this line is not really long ---------\n
And i am just chilling here"
我得到这样的信息(注意第二两行中的空格):
This is really long long line ---------------------------------------------------------------------------
And this line is not really long ---------
And i am just chilling here
其他选项根本不起作用。在这种情况下我如何遵守 yamllint 规则?
您看到此行为是因为您显式添加换行符,然后为文本的其余部分添加回车符。
您可以通过多种方式解决这个问题:
variable: "\
This is really long long line ---------------------\
------------------------------------------------------
\nAnd this line is not really long ---------
\nAnd i am just chilling here"
variable: "\
This is really long long line ---------------------\
------------------------------------------------------
And this line is not really long ---------
And i am just chilling here"
variable: |
This is really long long line ---------------------{#- -#}
------------------------------------------------------
And this line is not really long ---------
And i am just chilling here
This is really long long line ---------------------------------------------------------------------------
And this line is not really long ---------
And i am just chilling here