Nodejs String to HTML Convert toHtml()

Here you can find the source of toHtml()

Method Source Code

/**//from   w  w  w  . java  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;
}

Related

  1. toHtml()
    String.prototype.toHtml = function() {
        return this.replace(/<|>/ig, function(m){
            return '&'+(m =='>'?'g':'l')+'t;';
        })
    
  2. toHtml()
    String.prototype.toHtml = function () {
        var s = this;
        if (s.indexOf("://") > 0) {
            s = s.replace(/(^|[^\"\'\]])(http|ftp|mms|rstp|news|https)\:\/\/([^\s\033\[\]\"\']+)/gi, "$1[url]$2:
            s = s.replace(/\[url\](http\:\/\/\S+\.)(gif|jpg|jpeg|png)\[\/url\]/gi, "[img]$1$2[/img]");
        if (s.match(/\[(\w+)([^\[\]\s]*)\].*\[\/\1\]/)) {
            s = s.replace(/\[url\](.+?)\[\/url\]/gi, "<a href=$1 target=_blank>$1</a>");
            s = s.replace(/\[img\](.+?\.(?:gif|jpg|jpeg|png))\[\/img\]/gi, "<img src='$1' alt='$1'>");
    ...
    
  3. toHtmlString()
    String.prototype.toHtmlString = function() {
      return this.replace(/"/g, '&quot;');
    };