class MaRuKu::Section
A section in the table of contents of a document.
Attributes
The ‘:header` node for this section. The value of `meta` for the header will be this node.
@return [MDElement]
The immediate child nodes of this section.
@todo Why does this never contain Strings
?
@return [Array<MDElement>]
The subsections of this section.
@return [Array<Section>]
The depth of the section (0 for toplevel).
Equivalent to ‘header_element.level`.
@return [Fixnum]
The nested section number, e.g. ‘[1, 2, 5]` for Section
1.2.5.
@return [Array<Fixnum>]
Public Class Methods
Source
# File lib/maruku/toc.rb, line 34 def initialize @immediate_children = [] @section_children = [] end
Public Instance Methods
Source
# File lib/maruku/toc.rb, line 39 def inspect(indent = 1) if @header_element s = "\_" * indent << "(#{@section_level})>\t #{@section_number.join('.')} : " << @header_element.children_to_s << " (id: '#{@header_element.attributes[:id]}')\n" else s = "Master\n" end @section_children.each {|c| s << c.inspect(indent + 1) } s end
Source
# File lib/maruku/toc.rb, line 61 def numerate(a = []) self.section_number = a self.section_children.each_with_index {|c, i| c.numerate(a + [i + 1])} if h = self.header_element h.attributes[:section_number] = self.section_number end end
Assign {#section_number section numbers} to this section and its children. This also assigns the section number attribute to the sections’ headers.
This should only be called on the root section.
@overload def numerate
Source
# File lib/maruku/toc.rb, line 73 def to_html MaRuKu::Out::HTML::HTMLElement.new('div', { 'class' => 'maruku_toc' }, _to_html) end
Returns an HTML representation of the table of contents.
This should only be called on the root section.
Source
# File lib/maruku/toc.rb, line 80 def to_latex _to_latex + "\n\n" end
Returns a LaTeX representation of the table of contents.
This should only be called on the root section.
Protected Instance Methods
Source
# File lib/maruku/toc.rb, line 86 def _to_html ul = MaRuKu::Out::HTML::HTMLElement.new('ul') @section_children.each do |c| li = MaRuKu::Out::HTML::HTMLElement.new('li') if span = c.header_element.render_section_number li << span end a = c.header_element.wrap_as_element('a') a.attributes.delete('id') a['href'] = "##{c.header_element.attributes[:id]}" li << a li << c._to_html if c.section_children.size > 0 ul << li end ul end
Source
# File lib/maruku/toc.rb, line 105 def _to_latex s = "" @section_children.each do |c| s << "\\noindent" if number = c.header_element.section_number s << number end id = c.header_element.attributes[:id] text = c.header_element.children_to_latex s << "\\hyperlink{#{id}}{#{text}}" s << "\\dotfill \\pageref*{#{id}} \\linebreak\n" s << c._to_latex if c.section_children.size > 0 end s end