class Asciidoctor::Reader

def process(data, &block)

Private: Process raw input, used for the outermost reader.
def process(data, &block)
  raw_source = []
  include_depth = @document.attr('include-depth', 0).to_i
  data.each do |line|
    if inc = line.match(REGEXP[:include_macro])
      if inc[0].start_with? '\\'
        raw_source << line[1..-1]
      # if running in SafeMode::SECURE or greater, don't process
      # this directive (or should we swallow it?)
      elsif @document.safe >= SafeMode::SECURE
        raw_source << line
      # 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 block_given?
        raw_source.concat yield(inc[1])
      elsif include_depth > 0
        raw_source.concat File.readlines(@document.normalize_asset_path(inc[1], 'include file'))
      else
        raw_source << line
      end
    else
      raw_source << line
    end
  end
  skip_to = nil
  continuing_value = nil
  continuing_key = nil
  @lines = []
  raw_source.each do |line|
    # normalize line ending to LF (purging occurrences of CRLF)
    line = "#{line.rstrip}\n"
    if skip_to
      skip_to = nil if line.match(skip_to)
    elsif continuing_value
      close_continue = false
      # Lines that start with whitespace and end with a '+' are
      # a continuation, so gobble them up into `value`
      if line.match(REGEXP[:attr_continue])
        continuing_value += ' ' + $1.rstrip
      # An empty line ends a continuation
      elsif line.strip.empty?
        raw_source.unshift(line)
        close_continue = true
      else
        # If this continued line isn't empty and doesn't end with a +, then
        # this is the end of the continuation, no matter what the next line
        # does.
        continuing_value += ' ' + line.strip
        close_continue = true
      end
      if close_continue
        unless attribute_overridden? continuing_key
          @document.attributes[continuing_key] = apply_attribute_value_subs(continuing_value)
        end
        continuing_key = nil
        continuing_value = nil
      end
    elsif line.match(REGEXP[:ifdef_macro])
      attr = $2
      skip = case $1
             when 'ifdef';  !@document.attributes.has_key?(attr)
             when 'ifndef'; @document.attributes.has_key?(attr)
             end
      skip_to = /^endif::#{attr}\[\]\s*\n/ if skip
    elsif line.match(REGEXP[:attr_assign])
      key = sanitize_attribute_name($1)
      value = $2
      if value.match(REGEXP[:attr_continue])
        # attribute value continuation line; grab lines until we run out
        # of continuation lines
        continuing_key = key
        continuing_value = $1.rstrip  # strip off the spaces and +
      else
        unless attribute_overridden? key
          @document.attributes[key] = apply_attribute_value_subs(value)
          if key == 'backend'
            @document.update_backend_attributes()
          end
        end
      end
    elsif line.match(REGEXP[:attr_delete])
      key = sanitize_attribute_name($1)
      unless attribute_overridden? key
        @document.attributes.delete(key)
      end
    elsif !line.match(REGEXP[:endif_macro])
      while line.match(REGEXP[:attr_conditional])
        value = @document.attributes.has_key?($1) ? $2 : ''
        line.sub!(REGEXP[:attr_conditional], value)
      end
      # NOTE leave line comments in as they play a role in flow (such as a list divider)
      @lines << line
    end
  end
  # Process bibliography references, so they're available when text
  # before the reference is being rendered.
  # FIXME we don't have support for bibliography lists yet, so disable for now
  # plus, this should be done while we are walking lines above
  #@lines.each do |line|
  #  if biblio = line.match(REGEXP[:biblio])
  #    @document.register(:ids, biblio[1])
  #  end
  #end
end