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 content
foo
bar
baz
section.content
section << 'baz'
section << 'bar'
section << 'foo'
section = Section.new
Examples
Public: Get the String section content by aggregating rendered section blocks.
def content @blocks.map {|b| b.render }.join end
def generate_id
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' separator = @document.attr('idseparator', '_') base_id = @document.attr('idprefix', '_') + title.downcase.gsub(/&#[0-9]+;/, separator). gsub(/\W+/, separator).tr_s(separator, separator).chomp(separator) gen_id = base_id cnt = 2 while @document.references[:ids].has_key? gen_id gen_id = "#{base_id}#{separator}#{cnt}" cnt += 1 end @document.register(:ids, [gen_id, title]) gen_id else nil end end
def initialize(parent = nil, level = nil)
Public: Initialize an Asciidoctor::Section object.
def initialize(parent = nil, level = nil) super(parent, :section) if level.nil? && !parent.nil? @level = parent.level + 1 end if parent.is_a?(Section) && parent.special @special = true else @special = false end @index = 0 end
def render
Public: Get the rendered String content for this Section and all its child
def render Debug.debug { "Now rendering section for #{self}" } @document.playback_attributes @attributes renderer.render('section', self) end
def sectnum(delimiter = '.', append = nil)
# => 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 Section amongst its sibling Sections
the value of each entry is the 1-based index of
where each entry represents one level of nesting and
The section number is a unique, dot separated String
Public: Get the section number for the current Section
def sectnum(delimiter = '.', append = nil) append ||= (append == false ? '' : delimiter) if !@level.nil? && @level > 1 && @parent.is_a?(Section) "#{@parent.sectnum(delimiter)}#{@index + 1}#{append}" else "#{@index + 1}#{append}" end end
def to_s
def to_s if @title if @level && @index %[#{super.to_s} - #{sectnum} #@title [blocks:#{@blocks.size}]] else %[#{super.to_s} - #@title [blocks:#{@blocks.size}]] end else super.to_s end end