Created
July 5, 2015 23:58
-
-
Save JavaScript-Packer/bd38ff04d79553754432 to your computer and use it in GitHub Desktop.
My take on HTML entity encoding, escape HTML source code, make XML safe, etc. Thought I needed it for http://www.whak.ca/HTMLZIP.htm but didn't, so here it is the script:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function html_entities(me) { | |
| return me.replace(/^\s+|\s+$/g, "").replace(/(\r\n|\n|\r|\x0a)/gm, "\n").replace(/\n{2,}/g, "\n").replace(/\n/g, " ").replace(/\0/g, "�").replace(/\t{2,}/g, "\t").replace(/\x27/g, "'").replace(/\x22/g, """).replace(/ {2,}/g, " ").replace(/</g, "<").replace(/>/g, ">"); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment