class Asciidoctor::Extensions::Processor
def create_section parent, title, attrs, opts = {}
state of the sectnums document attribute (optional).
:numbered - [Boolean] A flag to force numbering, which falls back to the
one greater than the parent level (optional).
:level - [Integer] The level to assign to this section; defaults to
opts - An optional Hash of options (default: {}):
disable automatic ID generation (when sectids document attribute is set).
Use the id attribute to assign an explicit ID or set the value to false to
Use the style attribute to set the name of a special section (ex. appendix).
attrs - A Hash of attributes to control how the section is built.
title - The String title of the new Section.
parent - The parent Section (or Document) of this new Section.
Creates a Section node in the same manner as the parser.
Public: Creates a new Section node.
def create_section parent, title, attrs, opts = {} doc = parent.document book = (doctype = doc.doctype) == 'book' level = opts[:level] || parent.level + 1 if (style = attrs.delete 'style') if book && style == 'abstract' sectname, level = 'chapter', 1 else sectname, special = style, true level = 1 if level == 0 end elsif book sectname = level == 0 ? 'part' : (level > 1 ? 'section' : 'chapter') elsif doctype == 'manpage' && (title.casecmp 'synopsis') == 0 sectname, special = 'synopsis', true else sectname = 'section' end sect = Section.new parent, level sect.title, sect.sectname = title, sectname if special sect.special = true if opts.fetch :numbered, (style == 'appendix') sect.numbered = true elsif !(opts.key? :numbered) && (doc.attr? 'sectnums', 'all') sect.numbered = book && level == 1 ? :chapter : true end elsif level > 0 if opts.fetch :numbered, (doc.attr? 'sectnums') sect.numbered = sect.special ? parent.numbered && true : true end else sect.numbered = true if opts.fetch :numbered, (book && (doc.attr? 'partnums')) end if (id = attrs['id']) == false attrs.delete 'id' else sect.id = attrs['id'] = id || ((doc.attr? 'sectids') ? (Section.generate_id sect.title, doc) : nil) end sect.update_attributes attrs sect end