# File lib/asciidoctor/lexer.rb, line 1213
  def self.initialize_section(reader, parent, attributes = {})
    section = Section.new parent
    section.id, section.title, section.level, _ = parse_section_title(reader, section.document)
    # parse style, id and role from first positional attribute
    if attributes[1]
      section.sectname, _ = parse_style_attribute(attributes)
      section.special = true
      document = parent.document
      # HACK needs to be refactored so it's driven by config
      if section.sectname == 'abstract' && document.doctype == 'book'
        section.sectname = "sect1"
        section.special = false
        section.level = 1
      # FIXME refactor to use assign_caption (also check requirements)
      elsif section.sectname == 'appendix' &&
          !attributes.has_key?('caption') &&
          !document.attributes.has_key?('caption')
        number = document.counter('appendix-number', 'A')
        section.caption = "#{document.attributes['appendix-caption']} #{number}: "
        Document::AttributeEntry.new('appendix-number', number).save_to(attributes)
      end
    else
      section.sectname = "sect#{section.level}"
    end

    if section.id.nil? && (id = attributes['id'])
      section.id = id
    else
      # generate an id if one was not *embedded* in the heading line
      # or as an anchor above the section
      section.id ||= section.generate_id
    end

    if section.id
      section.document.register(:ids, [section.id, section.title])
    end
    section.update_attributes(attributes)
    reader.skip_blank_lines

    section
  end