# File lib/asciidoctor/parser.rb, line 1531
  def self.initialize_section reader, parent, attributes = {}
    document = parent.document
    source_location = reader.cursor if document.sourcemap
    sect_id, sect_reftext, sect_title, sect_level, atx = parse_section_title reader, document
    if sect_reftext
      attributes['reftext'] = sect_reftext
    elsif attributes.key? 'reftext'
      sect_reftext = attributes['reftext']
    #elsif document.attributes.key? 'reftext'
    #  sect_reftext = attributes['reftext'] = document.attributes['reftext']
    end

    # parse style, id, and role attributes from first positional attribute if present
    style = attributes[1] ? (parse_style_attribute attributes, reader) : nil
    if style
      if style == 'abstract' && document.doctype == 'book'
        sect_name, sect_level = 'chapter', 1
      else
        sect_name, sect_special = style, true
        sect_level = 1 if sect_level == 0
        sect_numbered_force = style == 'appendix'
      end
    else
      case document.doctype
      when 'book'
        sect_name = sect_level == 0 ? 'part' : (sect_level == 1 ? 'chapter' : 'section')
      when 'manpage'
        if (sect_title.casecmp 'synopsis') == 0
          sect_name, sect_special = 'synopsis', true
        else
          sect_name = 'section'
        end
      else
        sect_name = 'section'
      end
    end

    section = Section.new parent, sect_level, false
    section.id, section.title, section.sectname, section.source_location = sect_id, sect_title, sect_name, source_location
    # TODO honor special section numbering option (#661)
    if sect_special
      section.special = true
      section.numbered = true if sect_numbered_force
    elsif sect_level > 0 && (document.attributes.key? 'sectnums')
      section.numbered = section.special ? (parent.context == :section && parent.numbered) : true
    end

    # generate an ID if one was not embedded or specified as anchor above section title
    if (id = section.id ||= (attributes['id'] ||
        ((document.attributes.key? 'sectids') ? (Section.generate_id section.title, document) : nil)))
      unless document.register :refs, [id, section, sect_reftext || section.title]
        warn %(asciidoctor: WARNING: #{reader.path}: line #{reader.lineno - (atx ? 1 : 2)}: id assigned to section already in use: #{id})
      end
    end

    section.update_attributes(attributes)
    reader.skip_blank_lines

    section
  end