diff options
author | P. J. McDermott <pjm@nac.net> | 2012-08-10 14:29:35 (EDT) |
---|---|---|
committer | P. J. McDermott <pjm@nac.net> | 2012-08-10 14:29:35 (EDT) |
commit | b3fc81396147a4df176cd86cbf0e42e73fdc418f (patch) | |
tree | ef2b607ff63d24e24825649176dfbbd362645c42 /scripts/MarkdownBook/Document | |
parent | 9a90b5ef3d8f9572838700fa27ec568d29f76d64 (diff) |
Rewrite section code.
Diffstat (limited to 'scripts/MarkdownBook/Document')
-rw-r--r-- | scripts/MarkdownBook/Document/HTML.pm | 43 |
1 files changed, 15 insertions, 28 deletions
diff --git a/scripts/MarkdownBook/Document/HTML.pm b/scripts/MarkdownBook/Document/HTML.pm index ce19f45..a7e901a 100644 --- a/scripts/MarkdownBook/Document/HTML.pm +++ b/scripts/MarkdownBook/Document/HTML.pm @@ -17,6 +17,7 @@ use strict; use warnings; use MarkdownBook::Document; +use MarkdownBook::Section::HTML; package MarkdownBook::Document::HTML; @@ -26,24 +27,15 @@ sub parse_html { my ($self) = @_; my $file = $self->{'book'}->dir() . '/' . $self->{'file'} . '.html.in'; - - $self->{'tree'} = HTML::TreeBuilder->new(); - $self->{'tree'}->parse_file($file); -} - -sub number_sections -{ - my ($self) = @_; - my @headers; my $header; my @secnums = (0, 0); my $curlev = -1; my $newlev; my $secstr; - my @children; - my $sectitle; - my $secid; + + $self->{'tree'} = HTML::TreeBuilder->new(); + $self->{'tree'}->parse_file($file); @{$self->{'tree_body'}} = MarkdownBook::HTMLTree::find_elements_by_tag_names( $self->{'tree'}, ('body')); @@ -65,25 +57,20 @@ sub number_sections $secstr = join('.', @secnums); $secstr =~ s/(\.0)*$//; - MarkdownBook::HTMLTree::each_text(sub { - - # Prefix section title with section number. - my $sectitle = $_[1]; - $sectitle =~ s/^([^\[]+)[ ]*\[[^\]]+\]$/$_[2].$secstr $1/; - - # Set "id" attribute. - if ($_[1] =~ m/^[^\[\]]*\[([^\]]+)\][^\[\]]*$/) { - my $secid = $_[1]; - $secid =~ s/^[^\[\]]*\[([^\]]+)\][^\[\]]*$/$1/; - ${$_[0]}->attr('id', $secid); - } - - # Set section title. - $_[1] = $sectitle; + push(@{$self->{'sections'}}, + MarkdownBook::Section::HTML->new($self, $secstr, $header)); + } +} - }, $header, $self->{'id'}); +sub sections +{ + my ($self) = @_; + # FIXME: Why is this necessary?! + foreach my $sec (@{$self->{'sections'}}) { } + + return $self->{'sections'}; } sub output |