{{random}} split on :: to allow empty items & commas in items
This commit is contained in:
parent
389c2b5435
commit
2bed9fde70
|
@ -2124,8 +2124,8 @@ function randomReplace(input, emptyListPlaceholder = '') {
|
||||||
const randomPattern = /{{random[ : ]([^}]+)}}/gi;
|
const randomPattern = /{{random[ : ]([^}]+)}}/gi;
|
||||||
|
|
||||||
return input.replace(randomPattern, (match, listString) => {
|
return input.replace(randomPattern, (match, listString) => {
|
||||||
const list = listString.split(',').map(item => item.trim()).filter(item => item.length > 0);
|
//split on double colons instead of commas to allow for commas inside random items
|
||||||
|
const list = listString.split('::').filter(item => item.length > 0);
|
||||||
if (list.length === 0) {
|
if (list.length === 0) {
|
||||||
return emptyListPlaceholder;
|
return emptyListPlaceholder;
|
||||||
}
|
}
|
||||||
|
@ -2134,7 +2134,8 @@ function randomReplace(input, emptyListPlaceholder = '') {
|
||||||
const randomIndex = Math.floor(rng() * list.length);
|
const randomIndex = Math.floor(rng() * list.length);
|
||||||
|
|
||||||
//const randomIndex = Math.floor(Math.random() * list.length);
|
//const randomIndex = Math.floor(Math.random() * list.length);
|
||||||
return list[randomIndex];
|
//trim() at the end to allow for empty random values
|
||||||
|
return list[randomIndex].trim();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue