lib/maruku/toc.rb in maruku-0.2.13 vs lib/maruku/toc.rb in maruku-0.3.0

- old
+ new

@@ -16,10 +16,44 @@ # along with Maruku; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA require 'rexml/document' + +class Maruku + # an instance of Section (see below) + attr_accessor :toc +end + + + +class MDElement + # This represents a section in the TOC. + class Section + # a Fixnum, is == header_element.meta[:level] + attr_accessor :section_level + + # An array of fixnum, like [1,2,5] for Section 1.2.5 + attr_accessor :section_number + + # reference to header (header has h.meta[:section] to self) + attr_accessor :header_element + + # Array of immediate children of this element + attr_accessor :immediate_children + # Array of Section inside this section + attr_accessor :section_children + + + def initialize + @immediate_children = [] + @section_children = [] + end + end +end + + class MDElement class Section def inspect(indent=1) s = "" if @header_element @@ -132,10 +166,10 @@ # this level is inside s2 = Section.new s2.section_level = level s2.header_element = header - header.meta[:section] = s2 + header.instance_variable_set :@section, s2 stack.last.section_children.push s2 stack.push s2 i+=1 \ No newline at end of file