Skip to content

Commit

Permalink
corectly handle first line of multiline values
Browse files Browse the repository at this point in the history
  • Loading branch information
aproragadozo committed Nov 26, 2024
1 parent 82a9014 commit 1776ac2
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/convertToObject.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ function convertToObject(sourceString) {

let currentKey = null;
let currentValue = null;
let firstLinePreserved = false;

for (const line of processedString) {
// Check if this line is a new declaration
Expand All @@ -28,16 +29,20 @@ function convertToObject(sourceString) {
.replace(/;+$/, '')
.trim();

currentValue = [];
firstLinePreserved = false;
}

// Start a new declaration
const [key, ...valueParts] = line.split(':').map(part => part.trim());
currentKey = key;
// capture everything after the colon as a value
currentValue = valueParts.join(':').trim();
} else if (currentKey) {
firstLinePreserved = true;
} else if (currentKey && !firstLinePreserved) {
// This is a continuation of the previous value
currentValue += ',\n' + line.trim();
firstLinePreserved = true;
} else if(currentKey) {
currentValue += '\n' + line.trim();
}
}
Expand Down

0 comments on commit 1776ac2

Please sign in to comment.