npm package diff
Package: yaml
Versions: 2.2.1 - 2.2.2
File: package/browser/dist/stringify/stringifyString.js
Index: package/browser/dist/stringify/stringifyString.js
===================================================================
--- package/browser/dist/stringify/stringifyString.js
+++ package/browser/dist/stringify/stringifyString.js
@@ -1,9 +1,9 @@
import { Scalar } from '../nodes/Scalar.js';
import { foldFlowLines, FOLD_QUOTED, FOLD_FLOW, FOLD_BLOCK } from './foldFlowLines.js';
-const getFoldOptions = (ctx) => ({
- indentAtStart: ctx.indentAtStart,
+const getFoldOptions = (ctx, isBlock) => ({
+ indentAtStart: isBlock ? ctx.indent.length : ctx.indentAtStart,
lineWidth: ctx.options.lineWidth,
minContentWidth: ctx.options.minContentWidth
});
// Also checks for lines starting with %, as parsing the output as YAML 1.1 will
@@ -114,9 +114,9 @@
}
str = start ? str + json.slice(start) : json;
return implicitKey
? str
- : foldFlowLines(str, indent, FOLD_QUOTED, getFoldOptions(ctx));
+ : foldFlowLines(str, indent, FOLD_QUOTED, getFoldOptions(ctx, false));
}
function singleQuotedString(value, ctx) {
if (ctx.options.singleQuote === false ||
(ctx.implicitKey && value.includes('\n')) ||
@@ -126,9 +126,9 @@
const indent = ctx.indent || (containsDocumentMarker(value) ? ' ' : '');
const res = "'" + value.replace(/'/g, "''").replace(/\n+/g, `$&\n${indent}`) + "'";
return ctx.implicitKey
? res
- : foldFlowLines(res, indent, FOLD_FLOW, getFoldOptions(ctx));
+ : foldFlowLines(res, indent, FOLD_FLOW, getFoldOptions(ctx, false));
}
function quotedString(value, ctx) {
const { singleQuote } = ctx.options;
let qs;
@@ -224,9 +224,9 @@
.replace(/\n+/g, '\n$&')
.replace(/(?:^|\n)([\t ].*)(?:([\n\t ]*)\n(?![\n\t ]))?/g, '$1$2') // more-indented lines aren't folded
// ^ more-ind. ^ empty ^ capture next empty lines only at end of indent
.replace(/\n+/g, `$&${indent}`);
- const body = foldFlowLines(`${start}${value}${end}`, indent, FOLD_BLOCK, getFoldOptions(ctx));
+ const body = foldFlowLines(`${start}${value}${end}`, indent, FOLD_BLOCK, getFoldOptions(ctx, true));
return `${header}\n${indent}${body}`;
}
function plainString(item, ctx, onComment, onChompKeep) {
const { type, value } = item;
@@ -274,9 +274,9 @@
return quotedString(value, ctx);
}
return implicitKey
? str
- : foldFlowLines(str, indent, FOLD_FLOW, getFoldOptions(ctx));
+ : foldFlowLines(str, indent, FOLD_FLOW, getFoldOptions(ctx, false));
}
function stringifyString(item, ctx, onComment, onChompKeep) {
const { implicitKey, inFlow } = ctx;
const ss = typeof item.value === 'string'