Sha256: e2e0cdcebbb0978fbb90e7fc5f4da7e722be29ef1ad217f5ea0e6b851ae469f7
Contents?: true
Size: 1.08 KB
Versions: 7
Compression:
Stored size: 1.08 KB
Contents
module Nokogiri module HTML class DocumentFragment < Nokogiri::XML::DocumentFragment #### # Create a Nokogiri::XML::DocumentFragment from +tags+ def self.parse tags doc = HTML::Document.new doc.encoding = 'UTF-8' self.new(doc, tags) end def initialize document, tags = nil, ctx = nil return self unless tags children = if ctx ctx.parse("<div>#{tags.strip}</div>").first.children else ### # This is a horrible hack, but I don't care if tags.strip =~ /^<body/i path = "/html/body" else path = "/html/body/node()" end HTML::Document.parse( "<html><body>#{tags.strip}</body></html>", nil, document.encoding ).xpath(path) end children.each { |child| child.parent = self } end end end end
Version data entries
7 entries across 7 versions & 2 rubygems