lib/typogruby.rb in typogruby-1.0.16 vs lib/typogruby.rb in typogruby-1.0.17
- old
+ new
@@ -132,10 +132,14 @@
#
# @example Allows digits
# caps("A message from 2KU2 with digits")
# # => 'A message from <span class="caps">2KU2</span> with digits'
#
+ # @example Allows ampersands
+ # caps("A phone bill from AT&T")
+ # # => 'A phone bill from <span class="caps">AT&T</span>'
+ #
# @example Ignores HTML attributes
# caps('Download <a href="file.doc" title="PDF document">this file</a>')
# # => 'Download <a href="file.doc" title="PDF document">this file</a>'
#
# @example All caps with with apostrophes in them shouldn't break. Only handles dump apostrophes though.
@@ -154,13 +158,13 @@
# @return [String] input text with caps wrapped
def caps(text)
exclude_sensitive_tags(text) do |t|
# $1 and $2 are excluded HTML tags, $3 is the part before the caps and $4 is the caps match
t.gsub(%r{
- (<[^/][^>]*?>)| # Ignore any opening tag, so we don't mess up attribute values
- (\s| |^|'|"|>|) # Make sure our capture is preceded by whitespace or quotes
- ([A-Z\d](?:[\.']?[A-Z\d][\.']?){1,}) # Capture capital words, with optional dots or numbers in between
- (?!\w) # ...which must not be followed by a word character.
+ (<[^/][^>]*?>)| # Ignore any opening tag, so we don't mess up attribute values
+ (\s| |^|'|"|>|) # Make sure our capture is preceded by whitespace or quotes
+ ([A-Z\d](?:(\.|'|&|&|&\#38;)?[A-Z\d][\.']?){1,}) # Capture capital words, with optional dots, numbers or ampersands in between
+ (?!\w) # ...which must not be followed by a word character.
}x) do |str|
tag, before, caps = $1, $2, $3
# Do nothing with the contents if ignored tags, the inside of an opening HTML element
# so we don't mess up attribute values, or if our capture is only digits.