Skip to content

Instantly share code, notes, and snippets.

@flesch
Created August 18, 2012 15:30
Show Gist options
  • Save flesch/3387715 to your computer and use it in GitHub Desktop.
Save flesch/3387715 to your computer and use it in GitHub Desktop.
Replace the goofy characters Word uses.
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