Commit 8a6c3f27 authored by Yorick Peterse's avatar Yorick Peterse

Added ReferenceFilter#nodes

This method returns an Array of the HTML nodes as yielded by
ReferenceFilter#each_node. The method's return value is memoized to
allow multiple calls without having to re-query the input document.
parent 2fbfb854
......@@ -80,6 +80,11 @@ module Banzai
end
end
# Returns an Array containing all HTML nodes.
def nodes
@nodes ||= each_node.to_a
end
# Yields the link's URL and text whenever the node is a valid <a> tag.
def yield_valid_link(node)
link = CGI.unescape(node.attr('href').to_s)
......
......@@ -33,4 +33,13 @@ describe Banzai::Filter::ReferenceFilter, lib: true do
expect { |b| filter.each_node(&b) }.not_to yield_control
end
end
describe '#nodes' do
it 'returns an Array of the HTML nodes' do
document = Nokogiri::HTML.fragment('<a href="foo">foo</a>')
filter = described_class.new(document, project: project)
expect(filter.nodes).to eq([document.children[0]])
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment