From 22135732eaa0190ba6ba737d35443cf1d9751c73 Mon Sep 17 00:00:00 2001 From: P. J. McDermott Date: Sun, 12 Aug 2012 08:02:13 -0400 Subject: Include documents in sections list and ToC. --- diff --git a/scripts/MarkdownBook/Book.pm b/scripts/MarkdownBook/Book.pm index bb33f9f..3056a13 100644 --- a/scripts/MarkdownBook/Book.pm +++ b/scripts/MarkdownBook/Book.pm @@ -149,7 +149,10 @@ sub add_section my ($self, $section) = @_; push(@{$self->{'sections'}}, $section); - $self->{'sections_by_id'}->{$section->id()} = $section; + + if (ref($section) eq 'MarkdownBook::Section') { + $self->{'sections_by_id'}->{$section->id()} = $section; + } } sub subst_macros @@ -198,11 +201,19 @@ sub _do_gen_toc # TODO: Add chapters and appendices as well. foreach $section (@{$self->{'sections'}}) { $toc .= "\n" if $toc ne ''; - $toc .= ' ' x $section->level(); - $toc .= '* '; - $toc .= $section->number(); - $toc .= ' '; - $toc .= $section->title(); + if (ref($section) =~ m/^MarkdownBook::Document/) { + next if $section->type() eq 'index'; + $toc .= ' * '; + $toc .= $section->id(); + $toc .= ' '; + $toc .= $section->title(); + } elsif (ref($section) eq 'MarkdownBook::Section') { + $toc .= ' ' x $section->level(); + $toc .= ($section->level() == 1 ? ' - ' : ' * '); + $toc .= $section->number(); + $toc .= ' '; + $toc .= $section->title(); + } } return $toc; @@ -214,6 +225,7 @@ sub parse my $doc; foreach $doc (@{$self->{'docs'}}) { + $self->add_section($doc); $doc->parse(); } } -- cgit v0.9.1