########################################################################### # # StructuredHTMLPlug.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 StructuredHTMLPlug; use HTMLPlug; use ImagePlug; #use strict; # every perl program should have this! #no strict 'refs'; # make an exception so we can use variables as filehandles sub BEGIN { @StructuredHTMLPlug::ISA = ('HTMLPlug'); } my $arguments = []; my $options = { 'name' => "StructuredHTMLPlug", 'desc' => "{StructuredHTMLPlug.desc}", 'abstract' => "no", 'inherits' => "yes", 'args' => $arguments }; sub new { my ($class) = shift (@_); my ($pluginlist,$inputargs,$hashArgOptLists) = @_; push(@$pluginlist, $class); if(defined $arguments){ push(@{$hashArgOptLists->{"ArgList"}},@{$arguments});} if(defined $options) { push(@{$hashArgOptLists->{"OptList"}},$options)}; my $self = (defined $hashArgOptLists)? new HTMLPlug($pluginlist,$inputargs,$hashArgOptLists): new HTMLPlug($pluginlist,$inputargs); return bless $self, $class; } sub read { my $self = shift (@_); my ($pluginfo, $base_dir, $file, $metadata, $processor, $maxdocs, $gli) = @_; my $filename = $file; $filename = &util::filename_cat ($base_dir, $file) if $base_dir =~ /\w/; if ($filename =~ m/\.html?$/) { my $poss_doc_filename = $filename; $poss_doc_filename =~ s/\.html?$/.doc/; if (-e $poss_doc_filename) { # this file has already been processed by Word plugin return 0; } } return $self->SUPER::read(@_); } sub process { my $self = shift (@_); #my ($textref, $pluginfo, $base_dir, $file, $metadata, $doc_obj) = @_; my ($textref, $pluginfo, $base_dir, $file, $metadata, $doc_obj, $gli) = @_; my $outhandle = $self->{'outhandle'}; print $outhandle "StructuredHTMLPlug: processing $file\n" if $self->{'verbosity'} > 1; 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->{'tof_header'}&& $self->{'tof_header'}=~ /\S/) { $body_text =~ s/
{'tof_header'})[^>]*)>(.+?)<\/p>//isg; } } if (defined $self->{'title_header'} && $self->{'title_header'}=~ /\S/){ $self->{'title_header'} =~ s/^(\()(.*)(\))/$2/is; #$body_text =~ s/
{'title_header'})[^>]*)>(.+?)<\/p>/
{'title_header'})[^>]*)>(.+?)<\/p>/
{'title_header'})[^>]*)>(.+?)<\/p>/isg; #$doctitle = "
{'level1_header'})[^>]*)>(.+?)<\/p>/
{'level2_header'})[^>]*)>(.+?)<\/p>/
{'level3_header'})[^>]*)>(.+?)<\/p>/
]*>]*> ]*> etc tags
my @h_split = split(/