# File lib/asciidoctor/reader.rb, line 427
  def preprocess_include(target, raw_attributes)
    target = @document.sub_attributes target
    if target.empty?
      advance
      @next_line_preprocessed = false
      false
    # if running in SafeMode::SECURE or greater, don't process this directive
    # however, be friendly and at least make it a link to the source document
    elsif @document.safe >= SafeMode::SECURE
      @lines[0] = "link:#{target}[#{target}]\n"
      @next_line_preprocessed = true
      false
    # assume that if a block is given, the developer wants
    # to handle when and how to process the include, even
    # if the include-depth attribute is 0
    elsif @include_block
      advance
      # FIXME this borks line numbers
      @lines.unshift(*normalize_include_data(@include_block.call(target)))
    # FIXME currently we're not checking the upper bound of the include depth
    elsif @document.attributes.fetch('include-depth', 0).to_i > 0
      advance
      # FIXME this borks line numbers
      include_file = @document.normalize_system_path(target, nil, nil, :target_name => 'include file')
      if !File.file?(include_file)
        puts "asciidoctor: WARNING: line #{@lineno}: include file not found: #{include_file}"
        return true
      end

      inc_lines = nil
      tags = nil
      attributes = {}
      if !raw_attributes.empty?
        attributes = AttributeList.new(raw_attributes).parse
        if attributes.has_key? 'lines'
          inc_lines = []
          attributes['lines'].split(REGEXP[:ssv_or_csv_delim]).each do |linedef|
            if linedef.include?('..')
              from, to = linedef.split('..').map(&:to_i)
              if to == -1
                inc_lines << from
                inc_lines << 1.0/0.0
              else
                inc_lines.concat Range.new(from, to).to_a
              end
            else
              inc_lines << linedef.to_i
            end
          end
          inc_lines = inc_lines.sort.uniq
        elsif attributes.has_key? 'tags'
          tags = attributes['tags'].split(REGEXP[:ssv_or_csv_delim]).uniq
        end
      end
      if !inc_lines.nil?
        if !inc_lines.empty?
          selected = []
          f = File.new(include_file)
          f.each_line do |l|
            take = inc_lines.first
            if take.is_a?(Float) && take.infinite?
              selected.push l
            else
              if f.lineno == take
                selected.push l
                inc_lines.shift 
              end
              break if inc_lines.empty?
            end
          end
          @lines.unshift(*normalize_include_data(selected, attributes['indent'])) unless selected.empty?
        end
      elsif !tags.nil?
        if !tags.empty?
          selected = []
          active_tag = nil
          f = File.new(include_file)
          f.each_line do |l|
            l.force_encoding(::Encoding::UTF_8) if ::Asciidoctor::FORCE_ENCODING
            if !active_tag.nil?
              if l.include?("end::#{active_tag}[]")
                active_tag = nil
              else
                selected.push "#{l.rstrip}\n"
              end
            else
              tags.each do |tag|
                if l.include?("tag::#{tag}[]")
                  active_tag = tag
                  break
                end
              end
            end
          end
          #@lines.unshift(*selected) unless selected.empty?
          @lines.unshift(*normalize_include_data(selected, attributes['indent'])) unless selected.empty?
        end
      else
        @lines.unshift(*normalize_include_data(File.readlines(include_file), attributes['indent']))
      end
      true
    else
      @next_line_preprocessed = true
      false
    end
  end