_x000D_
var sourceElm = document.querySelector('input')_x000D_
_x000D_
// interpolation callback_x000D_
const onInterpolate = s => `<mark>${s}</mark>`_x000D_
_x000D_
// listen to "input" event_x000D_
sourceElm.addEventListener('input', parseInput) _x000D_
_x000D_
// parse on window load_x000D_
parseInput() _x000D_
_x000D_
// input element parser_x000D_
function parseInput(){_x000D_
var html = interpolate(sourceElm.value, undefined, onInterpolate)_x000D_
sourceElm.nextElementSibling.innerHTML = html;_x000D_
}_x000D_
_x000D_
// the actual interpolation _x000D_
function interpolate(str, interpolator = ["{{", "}}"], cb){_x000D_
// split by "start" pattern_x000D_
return str.split(interpolator[0]).map((s1, i) => {_x000D_
// first item can be safely ignored_x000D_
if( i == 0 ) return s1;_x000D_
// for each splited part, split again by "end" pattern _x000D_
const s2 = s1.split(interpolator[1]);_x000D_
_x000D_
// is there's no "closing" match to this part, rebuild it_x000D_
if( s1 == s2[0]) return interpolator[0] + s2[0]_x000D_
// if this split's result as multiple items' array, it means the first item is between the patterns_x000D_
if( s2.length > 1 ){_x000D_
s2[0] = s2[0] _x000D_
? cb(s2[0]) // replace the array item with whatever_x000D_
: interpolator.join('') // nothing was between the interpolation pattern_x000D_
}_x000D_
_x000D_
return s2.join('') // merge splited array (part2)_x000D_
}).join('') // merge everything _x000D_
}
_x000D_
input{ _x000D_
padding:5px; _x000D_
width: 100%; _x000D_
box-sizing: border-box;_x000D_
margin-bottom: 20px;_x000D_
}_x000D_
_x000D_
*{_x000D_
font: 14px Arial;_x000D_
padding:5px;_x000D_
}
_x000D_
<input value="Everything between {{}} is {{processed}}" />_x000D_
<div></div>
_x000D_