EBook-Tools

 view release on metacpan or  search on metacpan

lib/EBook/Tools/EReader.pm  view on Meta::CPAN

sub footnotes_html
{
    my $self = shift;
    my $subname = ( caller(0) )[3];
    debug(2,"DEBUG[",$subname,"]");

    my %footnotehash = $self->footnotes;
    my $text = '<h2 id="footnotes">Footnotes</h2>';
    $text .= "\n<dl>\n";

    foreach my $footnoteid (sort keys %footnotehash)
    {
        $text .= '<dt>[<a id="' . $footnoteid . '" href="#';
        $text .= $footnoteid . '-ref">' . $footnoteid;
        $text .= "</a>]</dt>\n";

        $text .= '<dd>' . $footnotehash{$footnoteid} . "</dd>\n";
    }
    $text .= "</dl>\n";
    $text = pml_to_html($text,$self->filebase);
    return $text;
}


=head2 C<pml()>

Returns a string containing the entire original document text in its
original encoding, including all sidebars and footnotes.

=cut

sub pml
{
    my $self = shift;
    my $subname = ( caller(0) )[3];
    debug(2,"DEBUG[",$subname,"]");
    debug(2,"DEBUG: returning ",length($self->{text})," bytes of PML text");
    return $self->{text} . "\n" . $self->sidebars_pml . $self->footnotes_pml;
}


=head2 C<html()>

Returns a string containing the entire document text (including all
sidebars and footnotes) converted to HTML.

Note that the PML text is stored in the object (and thus retrieving it
is very fast), but generating the HTML output requires that the text
be converted every time this method is used, consuming extra
processing time.

=cut

sub html
{
    my $self = shift;
    my $subname = ( caller(0) )[3];
    debug(2,"DEBUG[",$subname,"]");

    my $header = <<"END";
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
  <title>$self->{title}</title>
</head>
<body>
END
    my $footer = "</body>\n</html>\n";

    return
      $EBook::Tools::utf8xmldec . $header
        . pml_to_html($self->{text},$self->filebase)
        . $self->sidebars_html . $self->footnotes_html . $footer;
}


=head2 C<sidebars()>

Returns a hash containing all of the sidebars found in the file, where
the keys are the sidebar ids and the values contain the sidebar text.

=cut

sub sidebars
{
    my $self = shift;
    my $subname = ( caller(0) )[3];
    debug(2,"DEBUG[",$subname,"]");

    my %sidebarhash;
    my @sidebarids = ();
    my @sidebars = ();
    my $lastindex;

    if(ref $self->{sidebarids} eq 'ARRAY' and @{$self->{sidebarids}})
    {
        @sidebarids = @{$self->{sidebarids}};
    }

    if(ref $self->{sidebars} eq 'ARRAY' and @{$self->{sidebars}})
    {
        @sidebars = @{$self->{sidebars}};
    }

    if($#sidebars != $#sidebarids)
    {
        carp($subname,"(): found ",scalar(@sidebars)," sidebars but ",
             scalar(@sidebarids)," sidebar ids\n");
    }
    $lastindex = min($#sidebars, $#sidebarids);

    foreach my $idx (0 .. $lastindex)
    {
        $sidebarhash{$sidebarids[$idx]} = $sidebars[$idx];
    }

    return %sidebarhash;
}




( run in 1.718 second using v1.01-cache-2.11-cpan-59e3e3084b8 )