code: function encodeEntities(value) {
          return value.
              replace(/&/g, '&amp;').
              replace(surrogatePairRegexp, function(value) {
                  var hi = value.charCodeAt(0),
                      low = value.charCodeAt(1);
                  return '&#' + (((hi - 0xD800) * 0x400) + (low - 0xDC00) + 0x10000) + ';';
              }).
              replace(nonAlphanumericRegexp, function(value) {
                  return '&#' + value.charCodeAt(0) + ';';
              }).
              replace(/</g, '&lt;').
              replace(/>/g, '&gt;');
      }
docs: Message Text Formatting