This is kind of quick and dirty ,but how about something like this?
http://jsfiddle.net/rniemeyer/A7HDH/
It uses a custom binding that looks like:
ko.bindingHandlers.highlightedText = {
update: function(element, valueAccessor) {
var options = valueAccessor();
var value = ko.utils.unwrapObservable(options.text);
var search = ko.utils.unwrapObservable(options.highlight);
var css = ko.utils.unwrapObservable(options.css); //could be an observable
var value = $('<div/>').text(value).html(); //could do this or something similar to escape HTML before replacement, if necessary and the possibility of HTML injection exists in your value
var replacement = '<span class="' + css + '">' + search + '</span>';
element.innerHTML = value.replace(new RegExp(search, 'g'), replacement);
}
};
Then, you use it like:
<div data-bind="highlightedText: { text: name, highlight: searchText, css: 'highlight' }"></div>
<hr />
Name: <input data-bind="value: name" /><br/>
Search: <input data-bind="value: searchText" />
text, highlight, and css could all be observables.