UNPKG

323 BJavaScriptView Raw
1var htmlEncodeDict = {
2 '"': 'quot',
3 '<': 'lt',
4 '>': 'gt',
5 '&': 'amp',
6 ' ': 'nbsp'
7};
8
9/**
10 * HTML 编码
11 *
12 * @param {string} content 文本内容
13 */
14module.exports = function processor(content) {
15 return String(content).replace(/["<>& ]/g, function (all) {
16 return '&' + htmlEncodeDict[all] + ';';
17 });
18};
\No newline at end of file