Created
August 18, 2012 15:30
-
-
Save flesch/3387715 to your computer and use it in GitHub Desktop.
Replace the goofy characters Word uses.
This file contains 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
sanitize = (str, html) -> | |
replacements = | |
"\xa9": if html then "©" else "(c)", | |
"\xae": if html then "®" else "(r)", | |
"\u2018": "'", | |
"\u2019": "'", | |
"\u201c": if html then """ else "\"", | |
"\u201d": if html then """ else "\"", | |
"\u2026": "...", | |
"\u2013": if html then "–" else "-", | |
"\u2014": if html then "—" else "-", | |
"\u2122": if html then "™" else "(tm)" | |
for key, replacement of replacements | |
str = str.replace new RegExp(key, "g"), replacement | |
return str |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment