# File lib/webby/filters/outline.rb, line 114
  def filter
    doc = Hpricot.XML(@str)

    # extract directives from the "toc" tag
    toc_elem = doc.search('toc').first

    unless toc_elem.nil?
      @numbering = toc_elem['numbering'] !~ %r/off/i
      @numbering_start = Integer(toc_elem['numbering_start']) if toc_elem.has_attribute? 'numbering_start'
      @toc_style = toc_elem['toc_style'] if toc_elem.has_attribute? 'toc_style'
      @toc_range = toc_elem['toc_range'] if toc_elem.has_attribute? 'toc_range'
    end

    unless %w[ul ol].include? @toc_style
      raise ArgumentError, "unknown ToC list type '#{@toc_style}'"
    end

    m = %r/h(\d)\s*-\s*h(\d)/i.match @toc_range
    @toc_range = Integer(m[1])..Integer(m[2])
    @list_opening = build_list_opening(toc_elem)

    headers = @toc_range.map {|x| "h#{x}"}
    doc.traverse_element(*headers) do |elem|
      text, id = heading_info(elem)
      add_to_toc(text, id) if @toc_range.include? current_level
    end

    toc_elem.swap(toc) unless toc_elem.nil?
    doc.to_html
  end