class Asciidoctor::Section

def generate_id

=> "_foo_1"
another_section.generate_id
another_section.title = "Foo"
another_section = Section.new(parent)

=> "_foo"
section.generate_id
section.title = "Foo"
section = Section.new(parent)

Examples

until a unique id is found.
If the generated id is already in use in the document, a count is appended

Section id synthesis can be disabled by undefining the 'sectids' attribute.

is an underscore by default.
The generated id is prefixed with value of the 'idprefix' attribute, which

Public: Generate a String id for this section.
def generate_id
  if @document.attr?('sectids')
    base_id = @document.attr('idprefix', '_') + title.downcase.gsub(/&#[0-9]+;/, '_').
        gsub(/\W+/, '_').tr_s('_', '_').gsub(/^_?(.*?)_?$/, '\1')
    gen_id = base_id
    cnt = 2
    while @document.references[:ids].has_key? gen_id 
      gen_id = "#{base_id}_#{cnt}" 
      cnt += 1
    end 
    @document.references[:ids][gen_id] = title
    gen_id
  else
    nil
  end
end