Skip to content

Commit

Permalink
Include &, & and & in capitalised strings
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Robert Lloyd committed May 25, 2014
1 parent d4e3e86 commit 5d79f22
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
8 changes: 4 additions & 4 deletions lib/typogruby.rb
Expand Up @@ -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|&nbsp;|^|'|"|>|) # 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|&nbsp;|^|'|"|>|) # 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 (&, &amp; or &#38;) in between
(?!\w) # ...which must not be followed by a word character.
}x) do |str|
tag, before, caps = $1, $2, $3

Expand Down
4 changes: 3 additions & 1 deletion test/test_typogruby.rb
Expand Up @@ -44,7 +44,9 @@ def test_should_not_break_caps_with_apostrophes
end

def test_should_not_break_caps_with_ampersands
assert_equal '<span class="caps">AT&amp;T</span>', caps("AT&T")
assert_equal '<span class="caps">AT&T</span>', caps("AT&T")
assert_equal '<span class="caps">AT&amp;T</span>', caps("AT&amp;T")
assert_equal '<span class="caps">AT&#38;T</span>', caps("AT&#38;T")
end

def test_should_replace_quotes
Expand Down

0 comments on commit 5d79f22

Please sign in to comment.