Fix neohabitat json preprocessor

This commit is contained in:
Jeremy Penner 2024-01-06 00:11:07 -05:00
parent 93d05750bc
commit fcf52e08c5

View file

@ -30,16 +30,16 @@ const stringJoinRegex = /(("([^"]|\\")*"\s*\+\s*)+"([^"]|\\")*")/g;
function templateStringJoins(data) { function templateStringJoins(data) {
if (data.search(/\+/) != -1) { if (data.search(/\+/) != -1) {
return data.replace(/(\n)/g, '').replace(stringJoinRegex, return data.replace(/(\n)/g, '').replace(stringJoinRegex,
function(origText, offset, string) { function(origText, offset, string) {
var replacementText = []; var replacementText = [];
var splitText = origText.split('+'); var splitText = origText.split('+');
for (var textLineId in splitText) { for (var textLineId in splitText) {
var trimTextLine = splitText[textLineId].trim(); var trimTextLine = splitText[textLineId].trim();
var quotesRemoved = trimTextLine.replace(/(^")|("$)/g, ''); var quotesRemoved = trimTextLine.replace(/(^")|("$)/g, '');
replacementText.push(quotesRemoved); replacementText.push(quotesRemoved);
}
return `"${replacementText.join('')}"`
} }
return '"{0}"'.format(replacementText.join(''));
}
); );
} }
return data; return data;
@ -50,12 +50,12 @@ function templateConstantJoins(data) {
var replacementText = []; var replacementText = [];
var splitText = origText.split('+'); var splitText = origText.split('+');
for (var habConstId in splitText) { for (var habConstId in splitText) {
var trimHabConst = splitText[habConstId].trim(); var trimHabConst = splitText[habConstId].trim();
if (trimHabConst in joinReplacements) { if (trimHabConst in joinReplacements) {
replacementText.push(joinReplacements[trimHabConst]); replacementText.push(joinReplacements[trimHabConst]);
}
} }
} return `"${replacementText.join('')}"`
return '"{0}"'.format(replacementText.join(''));
}); });
} }