Skip to content

Commit b80be78

Browse files
committed
fix: handling of placeholder matching
1 parent 4478c11 commit b80be78

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

src/index.js

+15-5
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,10 @@ async function render({ source, element, selector, data, key, index, currentInde
200200

201201
await renderTemplate(element[i], data, key, index);
202202
}
203-
} else
204-
await renderValues(element[i], data);
203+
} else {
204+
let renderAs = element[i].getAttribute('render-as') || key;
205+
await renderValues(element[i], data, key, renderAs);
206+
}
205207

206208
}
207209

@@ -583,6 +585,8 @@ async function renderValues(node, data, key, renderAs, keyPath, parent) {
583585
async function renderValue(node, data, placeholder, renderAs, renderedNode) {
584586
let output = placeholder;
585587
let regex = /\{([^{}]+)\}/
588+
let omitted = {}
589+
586590
let match;
587591
do {
588592
match = output.match(regex);
@@ -633,19 +637,25 @@ async function renderValue(node, data, placeholder, renderAs, renderedNode) {
633637
if (typeof value === "object") {
634638
value = JSON.stringify(value, null, 2);
635639
}
636-
output = output.replace(match[0], value);
640+
output = output.replaceAll(match[0], value);
637641
} else if (renderAs) {
638642
if (match[0].startsWith(`{{${renderAs}.`)) {
639-
output = output.replace(match[0], "");
643+
output = output.replaceAll(match[0], "");
640644
} else {
641-
match = null;
645+
output = output.replaceAll(match[0], `<|${match[1]}|>`);
646+
omitted[`<|${match[1]}|>`] = match[0]
642647
}
643648
} else {
649+
// output = output.replace(match[0], `<|${match[1]}|>`);
644650
match = null;
645651
}
646652
}
647653
} while (match);
648654

655+
for (let key of Object.keys(omitted)) {
656+
output = output.replaceAll(key, omitted[key]);
657+
}
658+
649659
return output;
650660
}
651661

0 commit comments

Comments
 (0)