/**
* @description 解码
* @export
* @param {*} html
* @return {*}
*/
export function decodeHtml(html) {
return html && html.replace
? html
.replace(/ /gi, ' ')
.replace(/</gi, '<')
.replace(/>/g, '>')
.replace(/\/gi, '\\')
.replace(/'/gi, "'")
.replace(/"/gi, '"')
.replace(/<br\/>/gi, '\n')
.replace(/&/gi, '&')
: html;
}
/**
* @description 编码
* @export
* @param {*} html
* @return {*}
*/
export function encodeHtml(html) {
return html && html.replace
? html
.replace(/&/g, '&')
.replace(/ /g, ' ')
.replace(/\b +/g, ' ')
.replace(/</g, '<')
.replace(/>/g, '>')
.replace(/\\/g, '\')
// eslint-disable-next-line no-useless-escape
.replace(/\'/g, ''')
// eslint-disable-next-line no-useless-escape
.replace(/\"/g, '"')
.replace(/\n/g, '<br/>')
.replace(/\r/g, '')
: html;
}
Source