Skip to content

Instantly share code, notes, and snippets.

@njm2112
Forked from benrothe/SmartenQuotes.sh
Created December 24, 2016 17:17
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 njm2112/5bb3471b0734824a2357ddc5f0e7e16e to your computer and use it in GitHub Desktop.
Save njm2112/5bb3471b0734824a2357ddc5f0e7e16e to your computer and use it in GitHub Desktop.
A TextExpander snippet to convert clipboard contents: "Straight" quotes to “curly”, double-hyphens to em-dashes and three periods to ellipses.
#!/usr/bin/env php
<?php
$str = `pbpaste`;
$str = preg_replace('/(^|[-\xe2\x80\x94\/(\[{"\s])\'/', "$1\xe2\x80\x98", $str);
$str = preg_replace('/\'/', "\xe2\x80\x99", $str);
$str = preg_replace('/(^|[-\xe2\x80\x94\/(\[{\xe2\x80\x98\s])"/', "$1\xe2\x80\x9c", $str);
$str = preg_replace('/"/', "\xe2\x80\x9d", $str);
$str = preg_replace('/--/', "\xe2\x80\x94", $str);
$str = preg_replace('/\.\.\./', "\xe2\x80\xa6", $str);
echo $str;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment