Template string escaping fixes

Fixes #1209.
Can we just use JSON here?  And polyfill for the one host that doesn't support it?