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']
end
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
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
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