summaryrefslogtreecommitdiff
path: root/MistyCore/node_modules/yaml/browser/dist/stringify/stringifyDocument.js
diff options
context:
space:
mode:
authorMinteck <contact@minteck.org>2022-11-28 17:31:34 +0100
committerMinteck <contact@minteck.org>2022-11-28 17:31:34 +0100
commit7923aa8942b55884320ef2428417e3ee4b121613 (patch)
tree7993632f2898b1998f25b11ce40a8d2eb3d44730 /MistyCore/node_modules/yaml/browser/dist/stringify/stringifyDocument.js
downloadmistyos-og-mane.tar.gz
mistyos-og-mane.tar.bz2
mistyos-og-mane.zip
Initial commitHEADmane
Diffstat (limited to 'MistyCore/node_modules/yaml/browser/dist/stringify/stringifyDocument.js')
-rw-r--r--MistyCore/node_modules/yaml/browser/dist/stringify/stringifyDocument.js85
1 files changed, 85 insertions, 0 deletions
diff --git a/MistyCore/node_modules/yaml/browser/dist/stringify/stringifyDocument.js b/MistyCore/node_modules/yaml/browser/dist/stringify/stringifyDocument.js
new file mode 100644
index 0000000..e288c5d
--- /dev/null
+++ b/MistyCore/node_modules/yaml/browser/dist/stringify/stringifyDocument.js
@@ -0,0 +1,85 @@
+import { isNode } from '../nodes/Node.js';
+import { createStringifyContext, stringify } from './stringify.js';
+import { indentComment, lineComment } from './stringifyComment.js';
+
+function stringifyDocument(doc, options) {
+ const lines = [];
+ let hasDirectives = options.directives === true;
+ if (options.directives !== false && doc.directives) {
+ const dir = doc.directives.toString(doc);
+ if (dir) {
+ lines.push(dir);
+ hasDirectives = true;
+ }
+ else if (doc.directives.docStart)
+ hasDirectives = true;
+ }
+ if (hasDirectives)
+ lines.push('---');
+ const ctx = createStringifyContext(doc, options);
+ const { commentString } = ctx.options;
+ if (doc.commentBefore) {
+ if (lines.length !== 1)
+ lines.unshift('');
+ const cs = commentString(doc.commentBefore);
+ lines.unshift(indentComment(cs, ''));
+ }
+ let chompKeep = false;
+ let contentComment = null;
+ if (doc.contents) {
+ if (isNode(doc.contents)) {
+ if (doc.contents.spaceBefore && hasDirectives)
+ lines.push('');
+ if (doc.contents.commentBefore) {
+ const cs = commentString(doc.contents.commentBefore);
+ lines.push(indentComment(cs, ''));
+ }
+ // top-level block scalars need to be indented if followed by a comment
+ ctx.forceBlockIndent = !!doc.comment;
+ contentComment = doc.contents.comment;
+ }
+ const onChompKeep = contentComment ? undefined : () => (chompKeep = true);
+ let body = stringify(doc.contents, ctx, () => (contentComment = null), onChompKeep);
+ if (contentComment)
+ body += lineComment(body, '', commentString(contentComment));
+ if ((body[0] === '|' || body[0] === '>') &&
+ lines[lines.length - 1] === '---') {
+ // Top-level block scalars with a preceding doc marker ought to use the
+ // same line for their header.
+ lines[lines.length - 1] = `--- ${body}`;
+ }
+ else
+ lines.push(body);
+ }
+ else {
+ lines.push(stringify(doc.contents, ctx));
+ }
+ if (doc.directives?.docEnd) {
+ if (doc.comment) {
+ const cs = commentString(doc.comment);
+ if (cs.includes('\n')) {
+ lines.push('...');
+ lines.push(indentComment(cs, ''));
+ }
+ else {
+ lines.push(`... ${cs}`);
+ }
+ }
+ else {
+ lines.push('...');
+ }
+ }
+ else {
+ let dc = doc.comment;
+ if (dc && chompKeep)
+ dc = dc.replace(/^\n+/, '');
+ if (dc) {
+ if ((!chompKeep || contentComment) && lines[lines.length - 1] !== '')
+ lines.push('');
+ lines.push(indentComment(commentString(dc), ''));
+ }
+ }
+ return lines.join('\n') + '\n';
+}
+
+export { stringifyDocument };