Skip to content

Instantly share code, notes, and snippets.

@vancura
Forked from tomasc/typo.rb
Created October 5, 2010 14:19
Show Gist options
  • Save vancura/611634 to your computer and use it in GitHub Desktop.
Save vancura/611634 to your computer and use it in GitHub Desktop.
Typographic conversion regexps
def three_periods_to_ellipsis
self.gsub("...", "…")
end
def straight_double_quotes_to_smart_double_quotes
self.gsub(/\B"\b([^"“”„‟″‶\r\n]+)\b"\B/, '“\1”')
end
def straight_single_quotes_to_smart_single_quotes
self.gsub(/\B'\b([^'‘’‚‛′‵\r\n]+)\b'\B/, '‘\1’')
end
def straight_apostrophes_to_smart_apostrophes
self.gsub(/\b'\b/, '’');
end
def two_dashes_to_endash
self.gsub("--", "–")
end
def three_dashes_to_emdash
self.gsub("---", "—")
end
def endash_range
self.gsub(/(\d)(\s*-\s*)(\d)/, '\1–\3')
end
def emdash_between_words
self.gsub(/\b( +- +)\b/, ' — ')
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment