diff --git a/lib/typogruby.rb b/lib/typogruby.rb index 2f589c7..b703fba 100644 --- a/lib/typogruby.rb +++ b/lib/typogruby.rb @@ -160,10 +160,10 @@ 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, numbers or ampersands 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](?:[\.'&]?(?:amp;|#38;)?[A-Z\d][\.']?){1,}) # Capture capital words, with optional dots, numbers or ampersands (&, & or &) in between + (?!\w) # ...which must not be followed by a word character. }x) do |str| tag, before, caps = $1, $2, $3 diff --git a/test/test_typogruby.rb b/test/test_typogruby.rb index 417e8a3..77f4bda 100644 --- a/test/test_typogruby.rb +++ b/test/test_typogruby.rb @@ -44,7 +44,9 @@ def test_should_not_break_caps_with_apostrophes end def test_should_not_break_caps_with_ampersands - assert_equal 'AT&T', caps("AT&T") + assert_equal 'AT&T', caps("AT&T") + assert_equal 'AT&T', caps("AT&T") + assert_equal 'AT&T', caps("AT&T") end def test_should_replace_quotes