jquery - Convert Rtf to Html javascript -


i using jsfiddle convert html rtf. no expert in this.

 function converthtmltortf(html) {     if (!(typeof html === "string" && html)) {         return null;     }      var tmprichtext, hashyperlinks;     var richtext = html;      // singleton tags     richtext = richtext.replace(/<(?:hr)(?:\s+[^>]*)?\s*[\/]?>/ig, "{\\pard \\brdrb \\brdrs \\brdrw10 \\brsp20 \\par}\n{\\pard\\par}\n");     richtext = richtext.replace(/<(?:br)(?:\s+[^>]*)?\s*[\/]?>/ig, "{\\pard\\par}\n");      // empty tags     richtext = richtext.replace(/<(?:p|div|section|article)(?:\s+[^>]*)?\s*[\/]>/ig, "{\\pard\\par}\n");     richtext = richtext.replace(/<(?:[^>]+)\/>/g, "");      // hyperlinks     richtext = richtext.replace(         /<a(?:\s+[^>]*)?(?:\s+href=(["'])(?:javascript:void\(0?\);?|#|return false;?|void\(0?\);?|)\1)(?:\s+[^>]*)?>/ig,         "{{{\n");     tmprichtext = richtext;     richtext = richtext.replace(         /<a(?:\s+[^>]*)?(?:\s+href=(["'])(.+)\1)(?:\s+[^>]*)?>/ig,         "{\\field{\\*\\fldinst{hyperlink\n \"$2\"\n}}{\\fldrslt{\\ul\\cf1\n");     hashyperlinks = richtext !== tmprichtext;     richtext = richtext.replace(/<a(?:\s+[^>]*)?>/ig, "{{{\n");     richtext = richtext.replace(/<\/a(?:\s+[^>]*)?>/ig, "\n}}}");      // start tags     richtext = richtext.replace(/<(?:b|strong)(?:\s+[^>]*)?>/ig, "{\\b\n");     richtext = richtext.replace(/<(?:i|em)(?:\s+[^>]*)?>/ig, "{\\i\n");     richtext = richtext.replace(/<(?:u|ins)(?:\s+[^>]*)?>/ig, "{\\ul\n");     richtext = richtext.replace(/<(?:strike|del)(?:\s+[^>]*)?>/ig, "{\\strike\n");     richtext = richtext.replace(/<sup(?:\s+[^>]*)?>/ig, "{\\super\n");     richtext = richtext.replace(/<sub(?:\s+[^>]*)?>/ig, "{\\sub\n");     richtext = richtext.replace(/<(?:p|div|section|article)(?:\s+[^>]*)?>/ig, "{\\pard\n");      // end tags     richtext = richtext.replace(/<\/(?:p|div|section|article)(?:\s+[^>]*)?>/ig, "\n\\par}\n");     richtext = richtext.replace(/<\/(?:b|strong|i|em|u|ins|strike|del|sup|sub)(?:\s+[^>]*)?>/ig, "\n}");      // strip other remaining html tags [but leave contents]     richtext = richtext.replace(/<(?:[^>]+)>/g, "");      // prefix , suffix rich text necessary syntax     richtext =         "{\\rtf1\\ansi\n" + (hashyperlinks ? "{\\colortbl\n;\n\\red0\\green0\\blue255;\n}\n" : "") + richtext + "\n}";     return richtext; } 

now problem that: this fiddle not convert underlines, ignores new lines , bullets.

i using converter convert rtf html markupconverter in code.

this tool ignoring bullets , adding &nbsp @ end , in gaps..what do? how can fix these issues?


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -