Nodejs String to HTML Convert toHtml()

Here you can find the source of toHtml()

Method Source Code

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

Related

  1. toHtml()
    String.prototype.toHtml = function () {
        var s = this;
        s = s.replace(/\n/g, '</p><p>');
        s = '<p>' + s + '</p>';
        s = s.replace('<p></p>', '');
        return s;
    
  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;');
    };