summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorP. J. McDermott <pjm@nac.net>2012-08-12 08:02:13 (EDT)
committer P. J. McDermott <pjm@nac.net>2012-08-12 08:02:13 (EDT)
commit22135732eaa0190ba6ba737d35443cf1d9751c73 (patch)
tree57009c4391bd91431a9b1268cd29ffe0e58d824b
parent4f8f763f09a46b3e5a1d601951d90025528f8fda (diff)
Include documents in sections list and ToC.
-rw-r--r--scripts/MarkdownBook/Book.pm24
1 files changed, 18 insertions, 6 deletions
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();
}
}