Skip to content

Commit

Permalink
Merge pull request #158 from jch/revert-146-search_text_nodes
Browse files Browse the repository at this point in the history
Revert "Search for text nodes on DocumentFragments without root tags"
  • Loading branch information
jch committed Oct 7, 2014
2 parents e921fba + f6c5988 commit 980a61e
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 16 deletions.
4 changes: 2 additions & 2 deletions lib/html/pipeline/@mention_filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def self.mentioned_logins_in(text, username_pattern=UsernamePattern)
def call
result[:mentioned_usernames] ||= []

search_text_nodes(doc).each do |node|
doc.search('text()').each do |node|
content = node.to_html
next if !content.include?('@')
next if has_ancestor?(node, IGNORE_PARENTS)
Expand Down Expand Up @@ -132,4 +132,4 @@ def link_to_mentioned_user(login)
end
end
end
end
end
2 changes: 1 addition & 1 deletion lib/html/pipeline/emoji_filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Pipeline
# :asset_path (optional) - url path to link to emoji sprite. :file_name can be used as a placeholder for the sprite file name. If no asset_path is set "emoji/:file_name" is used.
class EmojiFilter < Filter
def call
search_text_nodes(doc).each do |node|
doc.search('text()').each do |node|
content = node.to_html
next unless content.include?(':')
next if has_ancestor?(node, %w(pre code tt))
Expand Down
7 changes: 0 additions & 7 deletions lib/html/pipeline/filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,6 @@ def doc
@doc ||= parse_html(html)
end

# Searches a Nokogiri::HTML::DocumentFragment for text nodes. If no elements
# are found, a second search without root tags is invoked.
def search_text_nodes(doc)
nodes = doc.xpath('.//text()')
nodes.empty? ? doc.xpath('text()') : nodes
end

# The String representation of the document. If a DocumentFragment was
# provided to the Filter, it is serialized into a String when this method is
# called.
Expand Down
6 changes: 0 additions & 6 deletions test/html/pipeline/emoji_filter_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@ def test_emojify
doc = filter.call
assert_match "https://foo.com/emoji/shipit.png", doc.search('img').attr('src').value
end

def test_emojify_on_string
filter = EmojiFilter.new(":shipit:", {:asset_root => 'https://foo.com'})
doc = filter.call
assert_match "https://foo.com/emoji/shipit.png", doc.search('img').attr('src').value
end

def test_uri_encoding
filter = EmojiFilter.new("<p>:+1:</p>", {:asset_root => 'https://foo.com'})
Expand Down

0 comments on commit 980a61e

Please sign in to comment.