// **Example Usage** // $.simpleFormat("this is first \n here is next line") // OR // $(".note").simpleFormat() (function($) { $.simpleFormat = function(str) { str = str.replace(/\r\n?/, "\n"); str = $.trim(str); if (str.length > 0) { str = str.replace(/\n\n+/g, "
");
str = str.replace(/\n/g, "
");
str = "
" + str + "
"; } return str; }; $.fn.simpleFormat = function() { return this.html($.simpleFormat(this.html())); }; })(jQuery);