|
NAMEHTML::GenToc - Generate a Table of Contents for HTML documents.VERSIONversion 3.20SYNOPSISuse HTML::GenToc; # create a new object my $toc = new HTML::GenToc(); my $toc = new HTML::GenToc(title=>"Table of Contents", toc_entry=>{ H1=>1, H2=>2 }, toc_end=>{ H1=>'/H1', H2=>'/H2' } ); # generate a ToC from a file $toc->generate_toc(input=>$html_file, footer=>$footer_file, header=>$header_file ); DESCRIPTIONHTML::GenToc generates anchors and a table of contents for HTML documents. Depending on the arguments, it will insert the information it generates, or output to a string, a separate file or STDOUT.While it defaults to taking H1 and H2 elements as the significant elements to put into the table of contents, any tag can be defined as a significant element. Also, it doesn't matter if the input HTML code is complete, pure HTML, one can input pseudo-html or page-fragments, which makes it suitable for using on templates and HTML meta-languages such as WML. Also included in the distrubution is hypertoc, a script which uses the module so that one can process files on the command-line in a user-friendly manner. DETAILSThe ToC generated is a multi-level level list containing links to the significant elements. HTML::GenToc inserts the links into the ToC to significant elements at a level specified by the user.Example: If H1s are specified as level 1, than they appear in the first level list of the ToC. If H2s are specified as a level 2, than they appear in a second level list in the ToC. Information on the significant elements and what level they should occur are passed in to the methods used by this object, or one can use the defaults. There are two phases to the ToC generation. The first phase is to put suitable anchors into the HTML documents, and the second phase is to generate the ToC from HTML documents which have anchors in them for the ToC to link to. For more information on controlling the contents of the created ToC, see "Formatting the ToC". HTML::GenToc also supports the ability to incorporate the ToC into the HTML document itself via the inline option. See "Inlining the ToC" for more information. In order for HTML::GenToc to support linking to significant elements, HTML::GenToc inserts anchors into the significant elements. One can use HTML::GenToc as a filter, outputing the result to another file, or one can overwrite the original file, with the original backed up with a suffix (default: "org") appended to the filename. One can also output the result to a string. METHODSDefault arguments can be set when the object is created, and overridden by setting arguments when the generate_toc method is called. Arguments are given as a hash of arguments.Method -- new$toc = new HTML::GenToc(); $toc = new HTML::GenToc(toc_entry=>\%my_toc_entry, toc_end=>\%my_toc_end, bak=>'bak', ... ); Creates a new HTML::GenToc object. These arguments will be used as defaults in invocations of other methods. See generate_tod for possible arguments. generate_toc$toc->generate_toc(outfile=>"index2.html"); my $result_str = $toc->generate_toc(to_string=>1); Generates a table of contents for the significant elements in the HTML documents, optionally generating anchors for them first. Options
(default:undefined)
INTERNAL METHODSThese methods are documented for developer purposes and aren't intended to be used externally.make_anchor_name$toc->make_anchor_name(content=>$content, anchors=>\%anchors); Makes the anchor-name for one anchor. Bases the anchor on the content of the significant element. Ensures that anchors are unique. make_anchorsmy $new_html = $toc->make_anchors(input=>$html, notoc_match=>$notoc_match, use_id=>$use_id, toc_entry=>\%toc_entries, toc_end=>\%toc_ends, ); Makes the anchors the given input string. Returns a string. make_toc_listmy @toc_list = $toc->make_toc_list(input=>$html, labels=>\%labels, notoc_match=>$notoc_match, toc_entry=>\%toc_entry, toc_end=>\%toc_end, filename=>$filename); Makes a list of lists which represents the structure and content of (a portion of) the ToC from one file. Also updates a list of labels for the ToC entries. build_lolBuild a list of lists of paths, given a list of hashes with info about paths.output_toc$self->output_toc(toc=>$toc_str, input=>\@input, filenames=>\@filenames); Put the output (whether to file, STDOUT or string). The "output" in this case could be the ToC, the modified (anchors added) HTML, or both. put_toc_inlinemy $newhtml = $toc->put_toc_inline(toc_str=>$toc_str, filename=>$filename, in_string=>$in_string); Puts the given toc_str into the given input string; returns a string. cpcp($src, $dst); Copies file $src to $dst. Used for making backups of files. FILE FORMATSFormatting the ToCThe toc_entry and other related options give you control on how the ToC entries may look, but there are other options to affect the final appearance of the ToC file created.With the header option, the contents of the given file (or string) will be prepended before the generated ToC. This allows you to have introductory text, or any other text, before the ToC.
With the toclabel option, the contents of the given string will be prepended before the generated ToC (but after any text taken from a header file). With the footer option, the contents of the file will be appended after the generated ToC.
If the header option is not specified, the appropriate starting HTML markup will be added, unless the toc_only option is specified. If the footer option is not specified, the appropriate closing HTML markup will be added, unless the toc_only option is specified. If you do not want/need to deal with header, and footer, files, then you are allowed to specify the title, title option, of the ToC file; and it allows you to specify a heading, or label, to put before ToC entries' list, the toclabel option. Both options have default values. If you do not want HTML page tags to be supplied, and just want the ToC itself, then specify the toc_only option. If there are no header or footer files, then this will simply output the contents of toclabel and the ToC itself. Inlining the ToCThe ability to incorporate the ToC directly into an HTML document is supported via the inline option.Inlining will be done on the first file in the list of files processed, and will only be done if that file contains an opening tag matching the toc_tag value. If overwrite is true, then the first file in the list will be overwritten, with the generated ToC inserted at the appropriate spot. Otherwise a modified version of the first file is output to either STDOUT or to the output file defined by the outfile option. The options toc_tag and toc_tag_replace are used to determine where and how the ToC is inserted into the output. Example 1 $toc->generate_toc(inline=>1, toc_tag => 'BODY', toc_tag_replace => 0, ... ); This will put the generated ToC after the BODY tag of the first file. If the header option is specified, then the contents of the specified file are inserted after the BODY tag. If the toclabel option is not empty, then the text specified by the toclabel option is inserted. Then the ToC is inserted, and finally, if the footer option is specified, it inserts the footer. Then the rest of the input file follows as it was before. Example 2 $toc->generate_toc(inline=>1, toc_tag => '!--toc--', toc_tag_replace => 1, ... ); This will put the generated ToC after the first comment of the form <!--toc-->, and that comment will be replaced by the ToC (in the order header toclabel ToC footer) followed by the rest of the input file.
NOTES
CAVEATS
BUGSTell me about them.REQUIRESThe installation of this module requires "Module::Build". The module depends on "HTML::SimpleParse", "HTML::Entities" and "HTML::LinkList" and uses "Data::Dumper" for debugging purposes. The hypertoc script depends on "Getopt::Long", "Getopt::ArgvFile" and "Pod::Usage". Testing of this distribution depends on "Test::More".INSTALLATIONTo install this module, run the following commands:perl Build.PL ./Build ./Build test ./Build install Or, if you're on a platform (like DOS or Windows) that doesn't like the "./" notation, you can do this: perl Build.PL perl Build perl Build test perl Build install In order to install somewhere other than the default, such as in a directory under your home directory, like "/home/fred/perl" go perl Build.PL --install_base /home/fred/perl as the first step instead. This will install the files underneath /home/fred/perl. You will then need to make sure that you alter the PERL5LIB variable to find the modules, and the PATH variable to find the script. Therefore you will need to change: your path, to include /home/fred/perl/script (where the script will be) PATH=/home/fred/perl/script:${PATH} the PERL5LIB variable to add /home/fred/perl/lib PERL5LIB=/home/fred/perl/lib:${PERL5LIB} SEE ALSOperl(1) htmltoc(1) hypertoc(1)AUTHORKathryn Andersen (RUBYKAT) http://www.katspace.org/tools/hypertoc/Based on htmltoc by Earl Hood ehood AT medusa.acs.uci.edu Contributions by Dan Dascalescu, <http://dandascalescu.com> COPYRIGHTCopyright (C) 1994-1997 Earl Hood, ehood AT medusa.acs.uci.edu Copyright (C) 2002-2008 Kathryn AndersenThis 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.
Visit the GSP FreeBSD Man Page Interface. |