0
@@ -15,7 +15,7 @@ module Filters
0
# into the heading tags, this can be specified in the attibutes of the
0
-# <toc
outline_numbering="off" />
0
+# <toc
numbering="off" />
0
# This will generate a table of contents, but not insert outline numbering
0
# into the heading tags.
0
@@ -29,11 +29,6 @@ class Outline
0
class Error < StandardError; end # :nodoc:
0
- # TODO: options for table of contents
0
- # - where to start numbering
0
- # - list style (numbered or unordered)
0
- # - header range to select (h2-h3)
0
@@ -46,8 +41,14 @@ class Outline
0
@cur_level, @base_level, @cur_depth = nil
0
- @outline_numbering = true
0
@@ -65,7 +66,7 @@ class Outline
0
# somewhere in a page about comic strips, the tag might be altered as such
0
- # <h3 id="h2_2_1"><span class="heading-num
>2.2.1</span>Get Fuzzy</h3>
0
+ # <h3 id="h2_2_1"><span class="heading-num
">2.2.1</span>Get Fuzzy</h3>
0
# The id attribute is used to generate a linke from the table of contents
0
# to this particular heading tag. The original text of the tag is used in
0
@@ -78,27 +79,46 @@ class Outline
0
toc_elem = doc.search('toc').first
0
- @outline_numbering = toc_elem['outline_numbering'] !~ %r/off/i
0
- @list_style = toc_elem['list'] || 'ol'
0
+ @numbering = toc_elem['numbering'] !~ %r/off/i
0
+ @numbering_start = Integer(toc_elem['numbering_start']) if toc_elem.has_attribute? 'numbering_start'
0
+ @toc_style = toc_elem['toc_style'] if toc_elem.has_attribute? 'toc_style'
0
+ @toc_range = toc_elem['toc_range'] if toc_elem.has_attribute? 'toc_range'
0
+ unless %w[ul ol].include? @toc_style
0
+ raise ArgumentError, "unknown ToC list type '#{@toc_style}'"
0
+ m = %r/h(\d)\s*-\s*h(\d)/i.match @toc_range
0
+ @toc_range = Integer(m[1])..Integer(m[2])
0
+ @list_opening = build_list_opening(toc_elem)
0
doc.traverse_element(*%w[h1 h2 h3 h4 h5 h6]) do |elem|
0
text, id = heading_info(elem)
0
+ add_to_toc(text, id)
if @toc_range.include? current_level0
- # create the TOC ordered list
0
toc_elem.swap(toc) unless toc_elem.nil?
0
- # replace the "toc" tag with the ordered list
0
+ def build_list_opening( elem )
0
+ %w[class style id].each do |atr|
0
+ next unless elem.has_attribute? atr
0
+ lo << " %s=\"%s\"" % [atr, elem[atr]]
0
+ if @toc_style == 'ol' and @numbering_start != 1
0
+ lo << " start=\"#{@numbering_start}\""
0
# Returns information for the given heading element. The information is
0
# returned as a two element array: [text, id].
0
@@ -114,7 +134,7 @@ class Outline
0
elem.children.first.before {tag!(:span, lbl, :class => 'heading-num')}
0
elem['id'] = "h#{lbl.tr('.','_')}" if elem['id'].nil?
0
@@ -131,8 +151,10 @@ class Outline
0
def current_level=( level )
0
+ @base_level = @cur_level = level
0
+ @level[@base_level-1] = @numbering_start-1
0
raise Error, "heading tags are not in order, cannot outline"
0
@@ -150,6 +172,12 @@ class Outline
0
+ # Returns the current heading level number.
0
# Return the label string for the current heading level.
0
@@ -178,8 +206,8 @@ class Outline
0
- lopen = "<#@list_style>"
0
- lclose = "</#@list_style>"
0
+ lopen = "<#@toc_style>"
0
+ lclose = "</#@toc_style>"
0
@@ -191,7 +219,7 @@ class Outline
0
# if we are increasing the level, then start a new list
0
+ ary <<
if ary.empty? then @list_opening else lopen end0
# we are decreasing the level; close out tags but ensure we don't
0
@@ -223,8 +251,8 @@ class Outline
0
# Returns +true+ if outline numbering should be inserted into the heading
0
# tags. Returns +false+ otherwise.
0
- def outline_numbering?
Comments
No one has commented yet.