summaryrefslogtreecommitdiffstats
path: root/scripts/MarkdownBook/Document
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/MarkdownBook/Document')
-rw-r--r--scripts/MarkdownBook/Document/HTML.pm43
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