Skip to content

Commit

Permalink
chore: improved htmlDecode script
Browse files Browse the repository at this point in the history
  • Loading branch information
anuraghazra committed Feb 8, 2020
1 parent 852c7fd commit e5594bd
Showing 1 changed file with 4 additions and 13 deletions.
17 changes: 4 additions & 13 deletions client/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,9 @@ export const getBugRefsFromMarkdown = (markdown: string): number[] => {
return matchedRefs || [];
};


// function htmlspecialchars(str) {
// }
// not sure if it's a good idea
export const htmlDecode = (input: string): string => {
const map: any = {
"&": "&",
"&lt;": "<",
"&gt;": ">",
"&quot;": "\"",
"&#39;": "'"
};
if (typeof input !== 'string') return '';
return input.replace(/(&amp;|&lt;|&gt;|&quot;|&#39;)/mg, (m) => map[m]);
};
const textarea = document.createElement("textarea");
textarea.innerHTML = input;
return textarea.value;
}

0 comments on commit e5594bd

Please sign in to comment.