re-usable text escaping

See https://bugs.dojotoolkit.org/ticket/8995