JavaScript to convert HTML Escape characters, jshtml escape characters

Source: Internet
Author: User

JavaScript to convert HTML Escape characters, jshtml escape characters

// Remove the html Tag

Function removeHtmlTab (tab) {return tab. replace (/<[^ <>] +?> /G, ''); // delete all HTML tags}

// Convert normal characters to escape characters

function html2Escape(sHtml) {  return sHtml.replace(/[<>&"]/g,function(c){return {'<':'<','>':'>','&':'&','"':'"'}[c];}); } 

// Replace the Italian character with a normal character

function escape2Html(str) {  var arrEntities={'lt':'<','gt':'>','nbsp':' ','amp':'&','quot':'"'};  return str.replace(/&(lt|gt|nbsp|amp|quot);/ig,function(all,t){return arrEntities[t];}); } 

// Convert it to a space

function nbsp2Space(str) {  var arrEntities = {'nbsp' : ' '};  return str.replace(/&(nbsp);/ig, function(all, t){return arrEntities[t]}) } 

// Press enter to convert to a br tag

function return2Br(str) {  return str.replace(/\r?\n/g,"<br />"); } 

// Remove the start and end line breaks and convert them into two line breaks three times in a row

Function trimBr (str) {str = str. replace (/(\ s |) * \ r? \ N) {3,}/g, "\ r \ n"); // limit up to 2 line breaks str = str. replace (/^ (\ s |) * \ r? \ N) +/g, ''); // clear str = str. replace (/(\ s |) * \ r? \ N) + $/g, ''); // clear the end line feed return str ;}

// Combine multiple consecutive spaces into one space

function mergeSpace(str) {  str=str.replace(/(\s| )+/g,' ');  return str; } 

The above JS conversion of HTML Escape characters is a small part of the Content shared to everyone, I hope to give you a reference, but also hope you can support a lot of help homes.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.