# File lib/asciidoctor/lexer.rb, line 1420
  def self.parse_header_metadata(reader, document = nil)
    # NOTE this will discard away any comment lines, but not skip blank lines
    process_attribute_entries(reader, document)

    metadata = {}
    implicit_author = nil
    implicit_authors = nil

    if reader.has_more_lines? && !reader.peek_line.chomp.empty?
      author_metadata = process_authors reader.get_line

      unless author_metadata.empty?
        # apply header subs and assign to document
        if !document.nil?
          author_metadata.map do |key, val|
            val = val.is_a?(String) ? document.apply_header_subs(val) : val
            document.attributes[key] = val if !document.attributes.has_key?(key)
            val
          end

          implicit_author = document.attributes['author']
          implicit_authors = document.attributes['authors']
        end

        metadata = author_metadata
      end

      # NOTE this will discard any comment lines, but not skip blank lines
      process_attribute_entries(reader, document)

      rev_metadata = {}

      if reader.has_more_lines? && !reader.peek_line.chomp.empty?
        rev_line = reader.get_line 
        if match = rev_line.match(REGEXP[:revision_info])
          rev_metadata['revdate'] = match[2].strip
          rev_metadata['revnumber'] = match[1].rstrip unless match[1].nil?
          rev_metadata['revremark'] = match[3].rstrip unless match[3].nil?
        else
          # throw it back
          reader.unshift_line rev_line
        end
      end

      unless rev_metadata.empty?
        # apply header subs and assign to document
        if !document.nil?
          rev_metadata.map do |key, val|
            val = document.apply_header_subs(val)
            document.attributes[key] = val if !document.attributes.has_key?(key)
            val
          end
        end

        metadata.update rev_metadata
      end

      # NOTE this will discard any comment lines, but not skip blank lines
      process_attribute_entries(reader, document)

      reader.skip_blank_lines
    end

    if !document.nil?
      # process author attribute entries that override (or stand in for) the implicit author line
      author_metadata = nil
      if document.attributes.has_key?('author') &&
          (author_line = document.attributes['author']) != implicit_author
        # do not allow multiple, process as names only
        author_metadata = process_authors author_line, true, false
      elsif document.attributes.has_key?('authors') &&
          (author_line = document.attributes['authors']) != implicit_authors
        # allow multiple, process as names only
        author_metadata = process_authors author_line, true
      else
        authors = []
        author_key = "author_#{authors.size + 1}"
        while document.attributes.has_key? author_key
          authors << document.attributes[author_key]
          author_key = "author_#{authors.size + 1}"
        end
        if authors.size == 1
          # do not allow multiple, process as names only
          author_metadata = process_authors authors.first, true, false
        elsif authors.size > 1
          # allow multiple, process as names only
          author_metadata = process_authors authors.join('; '), true
        end
      end

      unless author_metadata.nil?
        document.attributes.update author_metadata

        # special case
        if !document.attributes.has_key?('email') && document.attributes.has_key?('email_1')
          document.attributes['email'] = document.attributes['email_1']
        end
      end
    end

    metadata
  end