Skip to content

Instantly share code, notes, and snippets.

@dinhkhanh
Forked from drdrang/smarten.js
Created May 31, 2017 05:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dinhkhanh/c0e84f7b16c35f3ff5b7183deb9fd412 to your computer and use it in GitHub Desktop.
Save dinhkhanh/c0e84f7b16c35f3ff5b7183deb9fd412 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.
// 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