Last active
December 12, 2016 12:59
-
-
Save getflourish/1337e2d9b792c11f63cb9e5194194a2b to your computer and use it in GitHub Desktop.
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
importxxx |
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 smartypants(str) { | |
/* | |
Rules adapted from: | |
http://www.leancrew.com/all-this/2010/11/smart-quotes-in-javascript/ | |
*/ | |
return [ | |
[/(^|[-\u2014\s(\["])'/g, "$1\u2018"], // opening single quote | |
[/'/g, "\u2019"], // closing single quote, apostrophe | |
[/(^|[-\u2014/\[(\u2018\s])"/g, "$1\u201c"], // opening double quote | |
[/"/g, "\u201d"], // closing double quote | |
[/(\d)-(\d)/g, '$1\u2013$2'], // en dash in numerals | |
[/\s?-{2,3}\s?/g, '\u2009\u2014\u2009'], // em dash | |
[/\.{3}/g, '\u2026'] // ellipsis | |
].reduce(function(str, rule) { | |
return str.replace.apply(str, rule); | |
}, str); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment