Last active
August 29, 2015 14:04
-
-
Save kjantzer/503e46328ff692bfe38b to your computer and use it in GitHub Desktop.
Smart Quotes – changes straight double and single quotes to curly, double dashes to em-dashes, and triple periods to ellipsis.
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
| // http://stackoverflow.com/a/14890774/484780 | |
| smartQuotes = function(str){ | |
| return str = (str||'').replace(/\b'\b/g, "\u2019") // apostrophes | |
| .replace(/'(?=[^>]*<)\b/g, "\u2018") // Opening singles | |
| .replace(/\b([\.\?\!,]*)(?=[^>]*<)'/g, "$1\u2019") // Closing singles | |
| .replace(/"(?=[^>]*<)\b/g, "\u201c") // Opening doubles | |
| .replace(/\b([\.\?\!,]*)(?=[^>]*<)"/g, "$1\u201d") // Closing doubles | |
| .replace(/\.\.\./g, "\u2026") // ellipsis | |
| .replace(/--/g, "\u2014") // em-dashes | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment