Javascript String toHtml()

Description

Javascript String toHtml()


/**//from  ww w . j  a v  a  2  s  .  c o  m
 * Convert pre formated text to simple html
 */
String.prototype.toHtml = function () {
    var s = this;
    s = s.replace(/\n/g, '</p><p>');
    s = '<p>' + s + '</p>';
    s = s.replace('<p></p>', '');
    //this = s;
    return s;
}

Javascript String toHtml()

String.prototype.toHtml = function() {
    return this.replace(/<|>/ig, function(m){
        return '&'+(m =='>'?'g':'l')+'t;';
    })//from w w  w  .ja  v  a  2  s. c  o  m
}



PreviousNext

Related