Use XPath for searching link nodes

This is a tad faster than letting Nokogiri figure out whether it should
evaluate the query as CSS or XPath and then actually evaluating it.
This commit is contained in:
Yorick Peterse 2015-12-30 17:16:02 +01:00
parent ab08321be8
commit 3077cb52d9

View file

@ -124,7 +124,7 @@ module Banzai
def replace_link_nodes_with_text(pattern) def replace_link_nodes_with_text(pattern)
return doc if project.nil? return doc if project.nil?
doc.search('a').each do |node| doc.xpath('descendant-or-self::a').each do |node|
klass = node.attr('class') klass = node.attr('class')
next if klass && klass.include?('gfm') next if klass && klass.include?('gfm')
@ -162,7 +162,7 @@ module Banzai
def replace_link_nodes_with_href(pattern) def replace_link_nodes_with_href(pattern)
return doc if project.nil? return doc if project.nil?
doc.search('a').each do |node| doc.xpath('descendant-or-self::a').each do |node|
klass = node.attr('class') klass = node.attr('class')
next if klass && klass.include?('gfm') next if klass && klass.include?('gfm')