Skip to content

Commit

Permalink
Skip <tt> tags (EmojiFilter)
Browse files Browse the repository at this point in the history
  • Loading branch information
moskvax committed Oct 2, 2014
1 parent aeadfbd commit 4aef895
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/html/pipeline/emoji_filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def call
search_text_nodes(doc).each do |node|
content = node.to_html
next unless content.include?(':')
next if has_ancestor?(node, %w(pre code))
next if has_ancestor?(node, %w(pre code tt))
html = emoji_image_filter(content)
next if html == content
node.replace(html)
Expand Down
21 changes: 21 additions & 0 deletions test/html/pipeline/emoji_filter_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,25 @@ def test_custom_asset_path
doc = filter.call
assert_match "https://foo.com/%2B1.png", doc.search('img').attr('src').value
end

def test_not_emojify_in_code_tags
body = "<code>:shipit:</code>"
filter = EmojiFilter.new(body, {:asset_root => 'https://foo.com'})
doc = filter.call
assert_equal body, doc.to_html
end

def test_not_emojify_in_tt_tags
body = "<tt>:shipit:</tt>"
filter = EmojiFilter.new(body, {:asset_root => 'https://foo.com'})
doc = filter.call
assert_equal body, doc.to_html
end

def test_not_emojify_in_pre_tags
body = "<pre>:shipit:</pre>"
filter = EmojiFilter.new(body, {:asset_root => 'https://foo.com'})
doc = filter.call
assert_equal body, doc.to_html
end
end

0 comments on commit 4aef895

Please sign in to comment.