module Loofah::HtmlFragmentBehavior::ClassMethods

def document_klass

def document_klass
  @document_klass ||= if Loofah.html5_support? && self == Loofah::HTML5::DocumentFragment
    Loofah::HTML5::Document
  elsif self == Loofah::HTML4::DocumentFragment
    Loofah::HTML4::Document
  else
    raise ArgumentError, "unexpected class: #{self}"
  end
end

def parse(tags, encoding = nil)

def parse(tags, encoding = nil)
  doc = document_klass.new
  encoding ||= tags.respond_to?(:encoding) ? tags.encoding.name : "UTF-8"
  doc.encoding = encoding
  new(doc, tags)
end