Skip to content

Commit

Permalink
Add an options parameter to all the methods that allow creation of an…
Browse files Browse the repository at this point in the history
… HTML document fragment
  • Loading branch information
JackMc committed Mar 7, 2018
1 parent ec91453 commit 6767da7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions lib/nokogiri/html.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ def parse thing, url = nil, encoding = nil, options = XML::ParseOptions::DEFAULT

####
# Parse a fragment from +string+ in to a NodeSet.
def fragment string, encoding = nil
HTML::DocumentFragment.parse string, encoding
def fragment string, encoding = nil, options = nil, &block
HTML::DocumentFragment.parse string, encoding, options, &block
end
end

Expand Down
8 changes: 4 additions & 4 deletions lib/nokogiri/html/document_fragment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module HTML
class DocumentFragment < Nokogiri::XML::DocumentFragment
####
# Create a Nokogiri::XML::DocumentFragment from +tags+, using +encoding+
def self.parse tags, encoding = nil
def self.parse tags, encoding = nil, options = nil
doc = HTML::Document.new

encoding ||= if tags.respond_to?(:encoding)
Expand All @@ -19,10 +19,10 @@ def self.parse tags, encoding = nil

doc.encoding = encoding

new(doc, tags)
new(doc, tags, nil, options)
end

def initialize document, tags = nil, ctx = nil
def initialize document, tags = nil, ctx = nil, options = nil, &block
return self unless tags

if ctx
Expand All @@ -38,7 +38,7 @@ def initialize document, tags = nil, ctx = nil
path = "/html/body/node()"
end

temp_doc = HTML::Document.parse "<html><body>#{tags}", nil, document.encoding
temp_doc = HTML::Document.parse "<html><body>#{tags}", nil, document.encoding, options, &block
temp_doc.xpath(path).each { |child| child.parent = self }
self.errors = temp_doc.errors
end
Expand Down

0 comments on commit 6767da7

Please sign in to comment.