########################################################################### # # StructuredHTMLPlugin.pm -- html plugin with extra facilities for teasing out # hierarchical structure (such as h1, h2, h3, or user-defined tags) in an # HTML document # # A component of the Greenstone digital library software # from the New Zealand Digital Library Project at the # University of Waikato, New Zealand. # # Copyright (C) 1999 New Zealand Digital Library Project # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. # ########################################################################### # This plugin is to process an HTML file where sections are divided by # user-defined headings tags. As it is difficult to predict what user's definition # this plugin allows to detect the user-defined titles up to three levels (level1, level2, level3...) # as well as allows to get rid of user-defined Table of Content (TOC)... # format:e.g. level1 (Abstract_title|ChapterTitle|Referencing Heading) level2(SectionHeading)... package StructuredHTMLPlugin; use HTMLPlugin; use ImageConverter; # want the identify method use util; use strict; # every perl program should have this! no strict 'refs'; # make an exception so we can use variables as filehandles sub BEGIN { @StructuredHTMLPlugin::ISA = ('HTMLPlugin'); } my $arguments = [ { 'name' => "level1_header", 'desc' => "{StructuredHTMLPlugin.level1_header}", 'type' => "regexp", 'reqd' => "no", 'deft' => "" }, { 'name' => "level2_header", 'desc' => "{StructuredHTMLPlugin.level2_header}", 'type' => "regexp", 'reqd' => "no", 'deft' => "" }, { 'name' => "level3_header", 'desc' => "{StructuredHTMLPlugin.level3_header}", 'type' => "regexp", 'reqd' => "no", 'deft' => "" }, { 'name' => "title_header", 'desc' => "{StructuredHTMLPlugin.title_header}", 'type' => "regexp", 'reqd' => "no", 'deft' => "" }, { 'name' => "delete_toc", 'desc' => "{StructuredHTMLPlugin.delete_toc}", 'type' => "flag", 'reqd' => "no"}, { 'name' => "toc_header", 'desc' => "{StructuredHTMLPlugin.toc_header}", 'type' => "regexp", 'reqd' => "no", 'deft' => "" } ]; my $options = { 'name' => "StructuredHTMLPlugin", 'desc' => "{StructuredHTMLPlugin.desc}", 'abstract' => "no", 'inherits' => "yes", 'args' => $arguments }; sub new { my ($class) = shift (@_); my ($pluginlist,$inputargs,$hashArgOptLists) = @_; push(@$pluginlist, $class); push(@{$hashArgOptLists->{"ArgList"}},@{$arguments}); push(@{$hashArgOptLists->{"OptList"}},$options); my $self = new HTMLPlugin($pluginlist, $inputargs, $hashArgOptLists); return bless $self, $class; } sub process { my $self = shift (@_); my ($textref, $pluginfo, $base_dir, $file, $metadata, $doc_obj, $gli) = @_; my $outhandle = $self->{'outhandle'}; my @head_and_body = split(/
(.+)<\/title>/i; my $doctitle = $1 if defined $1; if (defined $self->{'metadata_fields'} && $self->{'metadata_fields'}=~ /\S/) { my @doc_properties = split(/{'toc_header'})[^>]*)>(.+?)<\/p>//isg; } } if (defined $self->{'title_header'} && $self->{'title_header'}=~ /\S/){ $self->{'title_header'} =~ s/^(\()(.*)(\))/$2/is; $body_text =~ s/
{'title_header'})[^>]*)>(.+?)<\/p>/
{'level1_header'})[^>]*)>(.+?)<\/p>/
{'level2_header'})[^>]*)>(.+?)<\/p>/
{'level3_header'})[^>]*)>(.+?)<\/p>/
]*>]*> ]*>,
etc tags
my @h_split = split(/
xxxx
element
$hc =~ s/^(\ \;)+/\ \;/g;
# boil HTML down to some interesting text
$h_text =~ s/^[1-3]>//;
$h_text =~ s/<\/?.*?>//sg;
$h_text =~ s/\s+/ /sg;
$h_text =~ s/^\s$//s;
$h_text =~ s/( )+\W*/ /sg;
if ($h_text =~ m/\w+/)
{
if ($new_hnum > $hnum)
{
# increase section nesting
$hnum++;
while ($hnum < $new_hnum)
{
my $spacing = " " x $hnum;
$section_text .= "\n";
$hnum++;
}
}
else # ($new_hnum <= $hnum)
{
# descrease section nesting
while ($hnum >= $new_hnum)
{
my $spacing = " " x $hnum;
$section_text .= "\n";
$hnum--;
}
$hnum++;
}
my $spacing = " " x $hnum;
$section_text .= "\n";
#print $outhandle $spacing."$h_text\n"
# if $self->{'verbosity'} > 2;
$sectionh1++ if ($hnum==1);
}
}
else {
### print STDERR "***** hc =