knockout.punches
knockout.punches copied to clipboard
Disable text interpolation for target block
Im does not found this option in docs. Is this exists?
Like:
<div class="{{ works }}">
<code data-bind="punches: false">
Some {{ example with }} {{ raw }} text
</code>
</div>
UPD Fastfix (slow and have bugs):
for (let node of document.body.querySelectorAll('[data-punches="false"]')) {
node.innerHTML = node.innerHTML
.replace(/(\{\{|\}\})/g, p => `{{"${p}"}}`)
}
UPD Fastfix No2 (does not work):
for (let node of document.body.querySelectorAll('[data-punches="false"]')) {
node.innerHTML = node.innerHTML
.replace(/\{\{/g, '{ {')
.replace(/\}\}/g, '} }');
}
UPD Fastfix No3 (works but has side effects)
for (let node of document.body.querySelectorAll('[data-punches="false"]')) {
node.innerHTML = node.innerHTML
.replace(/\{\{([\s\S]*?)\}\}/g, (i, j) => `{​{${j}}​}`)
}
I do not know how fix this trouble =(
See https://github.com/mbest/knockout.punches/issues/60
@jlaustill the code is not created dynamically
True, just thought it might provoke ideas since it was a similar issue :)
@jlaustill hmmm... yep, there are ideas, will think.
Thanks =)
Another variant:
ko.bindingHandlers.interpolation = {
init: (node, enabled) => {
if (!ko.unwrap(enabled())) {
node.innerHTML = node.innerHTML
.replace(/{{([\s\S]*?)}}/g, (i, j) => `{{${j}}​}`);
// ​ is a Magic Invisible Char
}
}
}
<div class="{{ works }}">
<code data-bind="interpolation: false">
Some {{ example with }} {{ raw }} text
</code>
</div>
In the source code did not find how to remove interpolation for the node
...
Try using allowBindings
as described in the Knockout docs.