-------------------------------------------------------------UPDATE----------------------------------------------------------
What I want - Eleborated:
How to fetch OR import all the special characters and their entity names from the below mentioned URL's to my htmlEscape function, I don't want to copy paste every single character and its entity name into .replace()
function manually, repeating the .replace() 300 times is difficult and NOT very programmatic.
OR
Is there a way to generate entity name from its character for instance I've a character <
and somehow a function generates its entity code <
.
HTML5 Special Characters: https://dev.w3.org/html5/html-author/charref
HTML3.2 Special Character: https://www.utexas.edu/learn/html/spchar.html
Note: The task I've require NO third party library.
Thanks, Help will be appreciate.
Backgrond:
Hey, I'm writing a custom function which will take the symbol and replace it with its entity name or number code, also I'm NOT looking for any 3rd party library. The symbol specification are from HTML 3.2 to HTML5, check the links bwlow. when i googled HTML special characters it turn out a lot more than i expected, if i keep repeating the code as below then i have to write every single symbol and its entity name or number code.
What I want - OLD:
Is there a better way to get the symbols and replace them with their entity name or number code because repeating the .replace 300 times is difficult and NOT very programmatic.
function htmlEscape(symbol)
{
return symbol
.replace(/-/g, "–").replace(/—/g, "—")
.replace(/¡/g, "¡").replace(/¿/g, "¿")
.replace(/“/g, "“").replace(/”/g, "”")
.replace(/‘/g, "&isquo;").replace(/’/g, "’")
.replace(/«/g, "«").replace(/»/g, "»")
.replace(/"/g, """).replace(/'/g, "'")
}