Hybrid raw/formatted html in preview

by Kehoru

HTML

<textarea name="" id="textareainput" cols="30" rows="10">
[b]bold[/b] normal <strong>strong</strong> <em>em</em> normal [i]italic[/i]<br /><br />

[code]we should see <strong>each</strong> html [u]tags[/u][/code]
</textarea>

<div class="preview"></div>

JavaScript

$('.preview').html( $('#textareainput').val() );

var bbcodeh = $('.preview').html().
  replace(/(\[((\/?)(b|u|i|s|sub|sup))\])/gi, '<$2>');

$('.preview').html(bbcodeh);