Permalink
Browse files

Support toc_depth option for ToC generation.

The config file may now contain a toc_depth key whose value is the maximum
depth to which header tags are considered for inclusion in the table of
contents. For example, if toc_depth = 3, only h2 and h3 tags are included in
the table of contents.
  • Loading branch information...
1 parent cd30099 commit b13057115dcaec6279fc93bb1702193c1cbbe912 @runpaint committed May 5, 2009
Showing with 3 additions and 1 deletion.
  1. +3 −1 lib/kitabu/base.rb
View
@@ -300,6 +300,7 @@ def self.to_permalink(str)
class Toc
include REXML::StreamListener
+ DEFAULT_MAX_DEPTH = 6
def initialize
@toc = ""
@@ -310,7 +311,8 @@ def initialize
def header?(tag=nil)
tag ||= @tag_name
- return false unless tag.to_s =~ /h[2-6]/
+ max_depth = Kitabu::Base.config['toc_depth'] || DEFAULT_MAX_DEPTH
+ return false unless tag.to_s =~ /h[2-#{max_depth}]/
@tag_name = tag
return true
end

1 comment on commit b130571

fnando commented on b130571 May 5, 2009

Cool! ;)

Please sign in to comment.