Created
November 18, 2010 14:51
-
-
Save drdrang/705071 to your computer and use it in GitHub Desktop.
A very simple quote and dash smartener in JS. Used to make my tweets look nicer.
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
// Change straight quotes to curly and double hyphens to em-dashes. | |
function smarten(a) { | |
a = a.replace(/(^|[-\u2014/(\[{"\s])'/g, "$1\u2018"); // opening singles | |
a = a.replace(/'/g, "\u2019"); // closing singles & apostrophes | |
a = a.replace(/(^|[-\u2014/(\[{\u2018\s])"/g, "$1\u201c"); // opening doubles | |
a = a.replace(/"/g, "\u201d"); // closing doubles | |
a = a.replace(/--/g, "\u2014"); // em-dashes | |
return a | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment