# File lib/nanoc/filters/relativize_paths.rb, line 31
    def run(content, params={})
      # Set assigns so helper function can be used
      @item_rep = assigns[:item_rep] if @item_rep.nil?

      # Filter
      case params[:type]
      when :css
        # FIXME parse CSS the proper way using csspool or something
        content.gsub(/url\((['"]?)(\/(?:[^\/].*?)?)\1\)/) do
          'url(' + $1 + relative_path_to($2) + $1 + ')'
        end
      when :html, :xml, :xhtml
        selectors  = params.fetch(:select) { SELECTORS }
        namespaces = params[:namespaces] || {}

        require 'nokogiri'
        case params[:type]
        when :html
          klass = ::Nokogiri::HTML
        when :xml
          klass = ::Nokogiri::XML
        when :xhtml
          klass = ::Nokogiri::XML
          # FIXME cleanup because it is ugly
          # this cleans the XHTML namespace to process fragments and full
          # documents in the same way. At least, Nokogiri adds this namespace
          # if detects the `html` element.
          content = content.sub(%r{(<html[^>]+)xmlns="http://www.w3.org/1999/xhtml"}, '\1')
        end

        nokogiri_process(content, selectors, namespaces, klass, params[:type])
      else
        raise RuntimeError.new(
          "The relativize_paths needs to know the type of content to " +
          "process. Pass a :type to the filter call (:html for HTML, " +
          ":xhtml for XHTML, :xml for XML, or :css for CSS).")
      end
    end