correctly substituting text for a dynamic placeholder see #527

This commit is contained in:
mic 2025-12-26 12:09:26 +01:00
parent 049b88302a
commit 5e8015161b

View file

@ -395,13 +395,17 @@ export const placeholdersUtils = {
use_default_value = false, use_default_value = false,
skip_additional_text = false skip_additional_text = false
} = args || {}; } = args || {};
console.log(">>>>>>>>>> replacePlaceholders replacements: " + JSON.stringify(replacements));
// Regular expression to match patterns like {%...%} // Regular expression to match patterns like {%...%}
return text.replace(/{%\s*(.*?)\s*%}/g, function(match, p1) { return text.replace(/{%\s*(.*?)\s*%}/g, function(match, p1) {
console.log(">>>>>>>>>> replacePlaceholders match: " + JSON.stringify(match));
console.log(">>>>>>>>>> replacePlaceholders p1: " + JSON.stringify(p1));
// p1 contains the key inside {% %} // p1 contains the key inside {% %}
if (skip_additional_text && (p1 === 'additional_text')) { if (skip_additional_text && (p1 === 'additional_text')) {
return match; return match;
} }
const currPlaceholder = defaultPlaceholders.find(ph => ph.id === p1); const currPlaceholder = defaultPlaceholders.find(ph => (ph.id === p1) || (ph.is_dynamic == 1 && p1.startsWith(ph.id + ':')));
console.log(">>>>>>>>>> replacePlaceholders currPlaceholder: " + JSON.stringify(currPlaceholder));
if (!currPlaceholder) { if (!currPlaceholder) {
return match; return match;
} }