Skip to content

Commit e51f63d

Browse files
authored
Update Convert_HTML_Entities.js
Moving object outside of the function for easier management.
1 parent 7d937bd commit e51f63d

1 file changed

Lines changed: 8 additions & 7 deletions

File tree

Convert_HTML_Entities.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
function convertHTML(str) {
2-
// :)
3-
const htmlChars = {
1+
var htmlChars = {
2+
"'": "'",
3+
'"': """, // tricky. :)
44
"<": "&lt;",
55
">": "&gt;",
6-
"'": "&apos;",
7-
'"': "&quot;",
8-
"&": "&amp;"
6+
"&": "&amp;",
97
};
10-
let regex = new RegExp("[" + Object.keys(htmlChars).join("") + "]", "g");
8+
9+
function convertHTML(str) {
10+
// &colon;&rpar;
11+
let regex = new RegExp("[" + Object.keys(htmlChars).join("") + "|^A-Za-z0-9"]", "g");
1112
return str.replace(regex, (x) => htmlChars[x]);
1213
}
1314

0 commit comments

Comments
 (0)