Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x | /**
* @browser safe functions
* @author heyli
* @date 2016.07.30
*/
/**
* html实体编码
* @param {String} str html文本
* @return {String} 经html实体编码后的html文本
*/
export function encodeHTML(str) {
// > 实体标签
// " Unicode 编码(可以用charCodeAt方法查看某字符对应的unicode编码)
let s = '';
Iif (!str || str.length === 0) return '';
s = str.replace(/&/g, '&');
s = s.replace(/</g, '<');
s = s.replace(/>/g, '>');
s = s.replace(/\'/g, ''');
s = s.replace(/\"/g, '"');
// 空格和换行其实可以不转
s = s.replace(/ /g, ' ');
s = s.replace(/\n/g, '<br>');
return s;
}
/**
* html实体编码转义
* @param {String} str html文本
* @return {String} 经html实体编码转义后的html文本
*/
export function decodeHTML(str) {
let s = '';
Iif (str.length === 0) return '';
s = str.replace(/&/g, '&');
s = s.replace(/</g, '<');
s = s.replace(/>/g, '>');
s = s.replace(/'/g, "\'");
s = s.replace(/"/g, '"');
s = s.replace(/ /g, ' ');
s = s.replace(/<br>/g, '\n');
return s;
}
|