summaryrefslogtreecommitdiffstats
path: root/scripts/MarkdownBook/Book.pm
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/MarkdownBook/Book.pm')
-rw-r--r--scripts/MarkdownBook/Book.pm28
1 files changed, 17 insertions, 11 deletions
diff --git a/scripts/MarkdownBook/Book.pm b/scripts/MarkdownBook/Book.pm
index 5047974..cf706a2 100644
--- a/scripts/MarkdownBook/Book.pm
+++ b/scripts/MarkdownBook/Book.pm
@@ -16,9 +16,6 @@
use strict;
use warnings;
-use MarkdownBook::Document::Txt;
-use MarkdownBook::Document::HTML;
-
package MarkdownBook::Book;
sub new
@@ -32,12 +29,15 @@ sub new
bless($self, $class);
if ($format eq 'html') {
+ use MarkdownBook::Document::HTML;
$self->{'format'} = 'html';
$self->{'format_mod'} = 'HTML';
} elsif ($format eq 'txt') {
+ use MarkdownBook::Document::Txt;
$self->{'format'} = 'txt';
$self->{'format_mod'} = 'Txt';
}
+
$self->{'dir'} = $dir;
$self->{'docs'} = [];
$self->{'sections'} = [];
@@ -88,7 +88,7 @@ sub documents
return $old;
}
-sub get_document_module
+sub _get_document_module
{
my ($self) = @_;
@@ -106,17 +106,19 @@ sub create_documents
my $doc_prev;
my @letters;
- $i = 0;
- $doc = $self->get_document_module()->new($self, 'index', 'index',
+ # Create index document.
+ $doc = $self->_get_document_module()->new($self, 'index', 'index',
undef, $self->{'title'});
$doc_prev = $doc;
push(@{$self->{'docs'}}, $doc);
+ # Create chapter documents.
+ $i = 0;
open($series_fh, '<', $self->{'dir'} . '/chapters');
while (<$series_fh>) {
chomp($_);
($file, $title) = split(/[ \t]+/, $_, 2);
- $doc = $self->get_document_module()->new($self, 'chapter', $file,
+ $doc = $self->_get_document_module()->new($self, 'chapter', $file,
++$i, $title);
$doc->prev($doc_prev);
$doc_prev->next($doc) if defined $doc_prev;
@@ -125,15 +127,15 @@ sub create_documents
}
close($series_fh);
+ # Create appendix documents.
$i = -1;
@letters = ('A' .. 'Z');
-
if (-e $self->{'dir'} . '/appendices') {
open($series_fh, '<', $self->{'dir'} . '/apendices');
while (<$series_fh>) {
chomp($_);
($file, $title) = split(/[ \t]+/, $_, 2);
- $doc = $self->get_document_module()->new($self, 'appendix', $file,
+ $doc = $self->_get_document_module()->new($self, 'appendix', $file,
$letters[++$i], $title);
$doc->prev($doc_prev);
$doc_prev->next($doc) if defined $doc_prev;
@@ -150,6 +152,7 @@ sub add_section
push(@{$self->{'sections'}}, $section);
+ # Index sections (not documents) by ID.
if (ref($section) eq 'MarkdownBook::Section') {
$self->{'sections_by_id'}->{$section->id()} = $section;
}
@@ -159,6 +162,7 @@ sub subst_macros
{
my ($self, $text) = @_;
+ # Substitute macros with arguments.
$text =~ s/
\$ # Dollar sign
\[ # Left square bracket
@@ -166,10 +170,12 @@ sub subst_macros
\] # Right square bracket
(
\[ # Left square bracket
- ([^\]]+) # Macro parameters
+ ([^\]]+) # Macro arguments
\] # Right square bracket
)
/$self->_do_subst_macro($1, split(m@[ \t]+@, $3))/exg;
+
+ # Substitute macros without arguments.
$text =~ s/
\$ # Dollar sign
\[ # Left square bracket
@@ -182,7 +188,7 @@ sub subst_macros
sub _do_subst_macro
{
- my ($self, $macro, @params) = @_;
+ my ($self, $macro, @args) = @_;
if ($macro eq 'toc') {
return $self->_do_gen_toc();