class Sanitize

def fragment(html)

Returns a sanitized copy of the given _html_ fragment.
def fragment(html)
  return '' unless html
  html = preprocess(html)
  doc  = Nokogiri::HTML5.parse("<html><body>#{html}")
  # Hack to allow fragments containing <body>. Borrowed from
  # Nokogiri::HTML::DocumentFragment.
  if html =~ /\A<body(?:\s|>)/i
    path = '/html/body'
  else
    path = '/html/body/node()'
  end
  frag = doc.fragment
  frag << doc.xpath(path)
  node!(frag)
  to_html(frag)
end