【发布时间】:2021-11-12 07:31:19
【问题描述】:
在 yaml 中,有多种方法可以将长字符串格式化为多行。例如:
输入:
example:
string1: An example of a long string that is split across
two lines
输出(作为 JSON):
{
"example": {
"string1": "An example of a long string that is split across two lines"
}
}
或者使用显式折叠语法:
example:
string1: >
An example of a long string that is split across
two lines
输出:
{
"example": {
"string1": "An example of a long string that is split across two lines"
}
}
或者使用文字语法:
example:
string1: |
An example of a long string that is split across
two lines
输出:
{
"example": {
"string1": "An example of a long string that is split across\ntwo lines"
}
}
在我能找到的所有示例中,似乎生成的字符串将在每行之间插入一个空格或换行符。但是,我想在几行上写一个很长的 yaml 字符串,在结果行中没有插入空格。这可能吗?
我的要求:
example:
string1: Oneverylongunbrokenlinethatmustnotcon
tainanyresultingwhitespaceintheoutput
期望的输出:
{
"example": {
"string1": "Oneverylongunbrokenlinethatmustnotcontainanyresultingwhitespaceintheoutput"
}
}
这样的语法存在吗?
【问题讨论】:
标签: yaml