class Asciidoctor::Section

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