summaryrefslogtreecommitdiff
path: root/lib/rdoc/markup/to_table_of_contents.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/rdoc/markup/to_table_of_contents.rb')
-rw-r--r--lib/rdoc/markup/to_table_of_contents.rb28
1 files changed, 27 insertions, 1 deletions
diff --git a/lib/rdoc/markup/to_table_of_contents.rb b/lib/rdoc/markup/to_table_of_contents.rb
index 54f2d5f64f..2e0f98cfeb 100644
--- a/lib/rdoc/markup/to_table_of_contents.rb
+++ b/lib/rdoc/markup/to_table_of_contents.rb
@@ -18,15 +18,31 @@ class RDoc::Markup::ToTableOfContents < RDoc::Markup::Formatter
attr_reader :res
+ ##
+ # Omits headings with a level less than the given level.
+
+ attr_accessor :omit_headings_below
+
def initialize # :nodoc:
super nil
+
+ @omit_headings_below = nil
+ end
+
+ ##
+ # Adds +document+ to the output, using its heading cutoff if present
+
+ def accept_document document
+ @omit_headings_below = document.omit_headings_below
+
+ super
end
##
# Adds +heading+ to the table of contents
def accept_heading heading
- @res << heading
+ @res << heading unless suppressed? heading
end
##
@@ -40,9 +56,19 @@ class RDoc::Markup::ToTableOfContents < RDoc::Markup::Formatter
# Prepares the visitor for text generation
def start_accepting
+ @omit_headings_below = nil
@res = []
end
+ ##
+ # Returns true if +heading+ is below the display threshold
+
+ def suppressed? heading
+ return false unless @omit_headings_below
+
+ heading.level > @omit_headings_below
+ end
+
# :stopdoc:
alias accept_block_quote ignore
alias accept_raw ignore