knockout/knockout — pull request #1022 by SteveSanderson (2013-07-01 11:42:12+00:00)
Title: Support node preprocessing in custom binding providers

This is a new extensibility point I'm keen to introduce to KO v3, as it paves the way for some powerful new features in the future. Right now it's a trivial change - just a couple of lines - which you can only use by implementing a custom binding provider. But later on we could use this to create some new features in the built-in binding provider.

### The idea

We already let custom bindings preprocess their binding string. This change takes that further, and **lets binding providers preprocess and mutate the DOM as they are binding it**. Two obvious and useful applications of this:

**1: String interpolation**. A binding provider can easily make syntax like `Name: {{ firstName }}` work by detecting `{{ expr }}` expressions in text nodes and inserting `` before binding applies to that node. This fixes what I think is the single most annoying thing about KO's existing syntax, which is having to write a ton of boilerplate markup just to display text. For this to be safe, we need commits 0f6e3c9 and c61abc7 too - see below.

**2: Custom elements**. A binding provider could look for a particular set of nonstandard elements, such as ``, and replace such elements with something like ``. Then if the developer also defined a ``, we'd have a super slick way of rendering custom widgets.

### Security and stability

Note that commits 0f6e3c9 and c61abc7 could be thought of as separate bugfixes, but I think it's worthwhile regarding them as part of the same package, because once we start showing people how to create a text interpolation binder (e.g., to make `Name: {{ firstName }}` work), then it's vital that we don't have new XSS concerns.