add yaml block support

This commit is contained in:
Jeremiah Snee 2025-09-30 10:39:24 -05:00
parent a09e74243f
commit 629d7134e4
No known key found for this signature in database
GPG Key ID: 1FF35A0EE683E0C6

View File

@ -20,6 +20,45 @@ function parseCollectionYaml(filePath) {
let currentArray = null;
let currentObject = null;
const readLiteralBlock = (startIndex, parentIndent) => {
const blockLines = [];
let blockIndent = null;
let index = startIndex;
for (; index < lines.length; index++) {
const rawLine = lines[index];
const trimmedLine = rawLine.trimEnd();
const contentOnly = trimmedLine.trim();
const lineIndent = rawLine.length - rawLine.trimLeft().length;
if (contentOnly === "" && blockIndent === null) {
// Preserve leading blank lines inside the literal block
blockLines.push("");
continue;
}
if (contentOnly !== "" && lineIndent <= parentIndent) {
break;
}
if (contentOnly === "") {
blockLines.push("");
continue;
}
if (blockIndent === null) {
blockIndent = lineIndent;
}
blockLines.push(rawLine.slice(blockIndent));
}
return {
content: blockLines.join("\n").replace(/\r/g, "").trimEnd(),
nextIndex: index - 1,
};
};
for (let i = 0; i < lines.length; i++) {
const line = lines[i];
const trimmed = line.trim();
@ -82,6 +121,10 @@ function parseCollectionYaml(filePath) {
result[key] = [];
}
currentKey = null; // Reset since we handled the array
} else if (value === "|" || value === ">") {
const { content: blockContent, nextIndex } = readLiteralBlock(i + 1, leadingSpaces);
result[key] = blockContent;
i = nextIndex;
} else {
result[key] = value;
}
@ -95,13 +138,25 @@ function parseCollectionYaml(filePath) {
}
} else if (currentObject && leadingSpaces > 0) {
// Property of current object (e.g., display properties)
if (value === "|" || value === ">") {
const { content: blockContent, nextIndex } = readLiteralBlock(i + 1, leadingSpaces);
currentObject[key] = blockContent;
i = nextIndex;
} else {
currentObject[key] = value === "true" ? true : value === "false" ? false : value;
}
} else if (currentArray && currentObject && leadingSpaces > 2) {
// Property of array item object
if (value === "|" || value === ">") {
const { content: blockContent, nextIndex } = readLiteralBlock(i + 1, leadingSpaces);
currentObject[key] = blockContent;
i = nextIndex;
} else {
currentObject[key] = value;
}
}
}
}
return result;
},