Unscramble effect in jQuery while maintaining the format

Unscramble effect in jQuery while maintaining the format

I'm using the unscramble plugin from Jason Frame's Grab Bag

But it seems only to work with text that has no format. I want that the text formatting remains unchanged.


The unscramble plugin:
  1. (function($) {
  2.         $.fn.unscramble = function() {
  3.             this.each(function() {
  4.                 var $ele = $(this), str = $ele.text(), replace = /[^\s]/,
  5.                     state = [], choose = [], reveal = 25, random = randomAlphaNum;
  6.                 
  7.                 for (var i = 0; i < str.length; i++) {
  8.                     if (str[i].match(replace)) {
  9.                         state.push(random());
  10.                         choose.push(i);
  11.                     } else {
  12.                         state.push(str[i]);
  13.                     }
  14.                 }
  15.                 
  16.                 shuffle(choose);
  17.                 $ele.text(state.join(''));
  18.                 
  19.                 var timer = setInterval(function() {
  20.                     var i, r = reveal;
  21.                     while (r-- && choose.length) {
  22.                         i = choose.pop();
  23.                         state[i] = str[i];
  24.                     }
  25.                     for (i = 0; i < choose.length; i++) state[choose[i]] = random();
  26.                     $ele.text(state.join(''));
  27.                     if (choose.length == 0) clearInterval(timer);
  28.                 }, 100);
  29.             });
  30.             return this;
  31.         };
  32. })(jQuery);

As you can see when pressed 'Unscramble me' the text format and the <br> tags are removed.

Due to my lack of skills in making jQuery plug-ins, I don't know what the problem is. I think it goes wrong when replacing /[^\s]/ but I'm not sure.

Somebody has an answer?

Thanks in advance.