class Asciidoctor::Section

> 1
section.size
section << new_block
=> “sect1”
section.id
=> 0
section.size
section.id = ‘sect1’
section.title = ‘Section 1’
section = Asciidoctor::Section.new
Examples
block-related methods to its @blocks Array.
The section responds as an Array of content blocks by delegating
Public: Methods for managing sections of AsciiDoc content in a document.

def self.generate_id title, document

Returns the generated [String] ID.

=> "_foo"
Section.generate_id 'Foo', document

Examples

Section ID generation can be disabled by unsetting the 'sectids' document attribute.

offset by the separator, until a unique ID is found.
If the generated ID is already in use in the document, a count is appended,

an underscore (_) by default.
spaces are replaced with the value of the 'idseparator' attribute, which is
is an underscore (_) by default. Invalid characters are then removed and
The generated ID is prefixed with value of the 'idprefix' attribute, which

Public: Generate a String ID from the given section title.
def self.generate_id title, document
  attrs = document.attributes
  pre = attrs['idprefix'] || '_'
  if (sep = attrs['idseparator'])
    if sep.length == 1 || (!(no_sep = sep.empty?) && (sep = attrs['idseparator'] = sep.chr))
      sep_sub = sep == '-' || sep == '.' ? ' .-' : %( #{sep}.-)
    end
  else
    sep, sep_sub = '_', ' _.-'
  end
  gen_id = %(#{pre}#{title.downcase.gsub InvalidSectionIdCharsRx, ''})
  if no_sep
    gen_id = gen_id.delete ' '
  else
    # replace space with separator and remove repeating and trailing separator characters
    gen_id = gen_id.tr_s sep_sub, sep
    gen_id = gen_id.chop if gen_id.end_with? sep
    # ensure id doesn't begin with idseparator if idprefix is empty (assuming idseparator is not empty)
    gen_id = gen_id.slice 1, gen_id.length if pre.empty? && (gen_id.start_with? sep)
  end
  if document.catalog[:refs].key? gen_id
    ids = document.catalog[:refs]
    cnt = Compliance.unique_id_start_index
    cnt += 1 while ids[candidate_id = %(#{gen_id}#{sep}#{cnt})]
    candidate_id
  else
    gen_id
  end
end

def << block

Returns The parent Block

block - The child Block to append to this parent Block

If the child block is a Section, assign an index to it.

Public: Append a content block to this block's list of blocks.
def << block
  assign_numeral block if block.context == :section
  super
end

def generate_id

See Section.generate_id for details.

Public: Generate a String ID from the title of this section.
def generate_id
  Section.generate_id title, @document
end

def initialize parent = nil, level = nil, numbered = false, opts = {}

opts - An optional Hash of options (default: {})
numbered - A Boolean indicating whether numbering is enabled for this Section (default: false)
level - The Integer level of this section (default: 1 more than parent level or 1 if parent not defined)
parent - The parent AbstractBlock. If set, must be a Document or Section object (default: nil)

Public: Initialize an Asciidoctor::Section object.
def initialize parent = nil, level = nil, numbered = false, opts = {}
  super parent, :section, opts
  if Section === parent
    @level, @special = level || (parent.level + 1), parent.special
  else
    @level, @special = level || 1, false
  end
  @numbered = numbered
  @index = 0
end

def sections?

Returns A [Boolean] to indicate whether this Section has child Section objects

Public: Check whether this Section has any child Section objects.
def sections?
  @next_section_index > 0
end

def sectnum(delimiter = '.', append = nil)

Returns the section number as a String

# => 1,1,1
sect1_1_1.sectnum(',', false)

# => 1.1.1.
sect1_1_1.sectnum

# => 1.2.
sect1_2.sectnum

# => 1.1.
sect1_1.sectnum

# => 1.
sect1.sectnum

sect1_1 << sect1_1_1
sect1_1_1.level = 3
sect1_1_1 = Section.new(sect1_1)
sect1 << sect1_2
sect1 << sect1_1
sect1_2.level = 2
sect1_2 = Section.new(sect1)
sect1_1.level = 2
sect1_1 = Section.new(sect1)
sect1.level = 1
sect1 = Section.new(document)

Examples

(default: nil)
appended to the final level
or Boolean to indicate the delimiter should not be
append - the String to append at the end of the section number
delimiter - the delimiter to separate the number for each level

The method also assumes that the value of @parent is either a Document or Section.
This method assumes that both the @level and @parent instance variables have been assigned.

the 1-based outline number of the Section amongst its numbered sibling Sections.
Section in the document. Each entry represents a level of nesting. The value of each entry is
The section number is a dot-separated String that uniquely describes the position of this

Public: Get the section number for the current Section
def sectnum(delimiter = '.', append = nil)
  append ||= (append == false ? '' : delimiter)
  @level > 1 && Section === @parent ? %(#{@parent.sectnum(delimiter, delimiter)}#{@numeral}#{append}) : %(#{@numeral}#{append})
end

def to_s

def to_s
  if @title
    formal_title = @numbered ? %(#{sectnum} #{@title}) : @title
    %(#<#{self.class}@#{object_id} {level: #{@level}, title: #{formal_title.inspect}, blocks: #{@blocks.size}}>)
  else
    super
  end
end

def xreftext xrefstyle = nil

(see AbstractBlock#xreftext)
def xreftext xrefstyle = nil
  if (val = reftext) && !val.empty?
    val
  elsif xrefstyle
    if @numbered
      case xrefstyle
      when 'full'
        if (type = @sectname) == 'chapter' || type == 'appendix'
          quoted_title = sub_placeholder (sub_quotes '_%s_'), title
        else
          quoted_title = sub_placeholder (sub_quotes @document.compat_mode ? %q(``%s'') : '"`%s`"'), title
        end
        if (signifier = @document.attributes[%(#{type}-refsig)])
          %(#{signifier} #{sectnum '.', ','} #{quoted_title})
        else
          %(#{sectnum '.', ','} #{quoted_title})
        end
      when 'short'
        if (signifier = @document.attributes[%(#{@sectname}-refsig)])
          %(#{signifier} #{sectnum '.', ''})
        else
          sectnum '.', ''
        end
      else # 'basic'
        (type = @sectname) == 'chapter' || type == 'appendix' ? (sub_placeholder (sub_quotes '_%s_'), title) : title
      end
    else # apply basic styling
      (type = @sectname) == 'chapter' || type == 'appendix' ? (sub_placeholder (sub_quotes '_%s_'), title) : title
    end
  else
    title
  end
end