| 1 | #!/usr/bin/env perl | ||||||||||
| 2 | 4 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | |||||||||||
| 4 | =head1 NAME | ||||||||||
| 5 | |||||||||||
| 6 | hypertoc - generate a table of contents for HTML documents | ||||||||||
| 7 | |||||||||||
| 8 | =head1 VERSION | ||||||||||
| 9 | |||||||||||
| 10 | version 3.20 | ||||||||||
| 11 | |||||||||||
| 12 | =head1 SYNOPSIS | ||||||||||
| 13 | |||||||||||
| 14 | hypertoc --help | --manpage | --man_help | --man | ||||||||||
| 15 | |||||||||||
| 16 | hypertoc [--bak I<string> ] [ --debug ] [ --entrysep I<string> ] | ||||||||||
| 17 | [ --footer I<file> ] [ --header I<file> ] [ --ignore_only_one ] | ||||||||||
| 18 | [ --ignore_sole_first ] [ --inline ] [ --make_anchors ] [ --make_toc ] | ||||||||||
| 19 | [ --notoc_match I<string> ] [ --ol | --nool ] [ --ol_num_levels ] | ||||||||||
| 20 | [ --outfile I<file> ] [ --overwrite ] [ --quiet ] [ --textonly ] | ||||||||||
| 21 | [ --title I<string> ] { --toc_after I<tag=suffix> } | ||||||||||
| 22 | { --toc_before I<tag=prefix> } { --toc_end I<tag=endtag> } | ||||||||||
| 23 | { --toc_entry I<tag=level> } [ --toc_label I<string> ] | ||||||||||
| 24 | [ --toc_only | --notoc_only ] [ --toc_tag I<string> ] | ||||||||||
| 25 | [ --toc_tag_replace ] [ --use_id ] [ --useorg ] file ... | ||||||||||
| 26 | |||||||||||
| 27 | =head1 DESCRIPTION | ||||||||||
| 28 | |||||||||||
| 29 | hypertoc allows you to specify "significant elements" that will be | ||||||||||
| 30 | hyperlinked to in a "Table of Contents" (ToC) for a given set of HTML | ||||||||||
| 31 | documents. | ||||||||||
| 32 | |||||||||||
| 33 | Basically, the ToC generated is a multi-level level list containing | ||||||||||
| 34 | links to the significant elements. hypertoc inserts the links into the | ||||||||||
| 35 | ToC to significant elements at a level specified by the user. | ||||||||||
| 36 | |||||||||||
| 37 | B<Example:> | ||||||||||
| 38 | |||||||||||
| 39 | If H1s are specified as level 1, than they appear in the first | ||||||||||
| 40 | level list of the ToC. If H2s are specified as a level 2, than | ||||||||||
| 41 | they appear in a second level list in the ToC. | ||||||||||
| 42 | |||||||||||
| 43 | There are two aspects to the ToC generation: (1) putting suitable anchors into | ||||||||||
| 44 | the HTML documents (--make_anchors), and (2) generating the ToC from HTML | ||||||||||
| 45 | documents which have anchors in them for the ToC to link to (--make_toc). | ||||||||||
| 46 | One can choose to do one or both of these. | ||||||||||
| 47 | |||||||||||
| 48 | hypertoc also supports the ability to incorporate the ToC into the HTML | ||||||||||
| 49 | document itself via the --inline option. | ||||||||||
| 50 | |||||||||||
| 51 | In order for hypertoc to support linking to significant elements, | ||||||||||
| 52 | hypertoc inserts anchors into the significant elements. One can | ||||||||||
| 53 | use hypertoc as a filter, outputing the result to another file, | ||||||||||
| 54 | or one can overwrite the original file, with the original backed | ||||||||||
| 55 | up with a suffix (default: "org") appended to the filename. | ||||||||||
| 56 | |||||||||||
| 57 | One can also define options in a config file as well as on the command-line. | ||||||||||
| 58 | |||||||||||
| 59 | =head1 OPTIONS | ||||||||||
| 60 | |||||||||||
| 61 | Options can start with "--" or "-"; boolean options can be negated | ||||||||||
| 62 | by preceding them with "no"; options with hash or array values | ||||||||||
| 63 | can be added to by giving the option again for each value. | ||||||||||
| 64 | |||||||||||
| 65 | See L<Getopt::Long> for more information. | ||||||||||
| 66 | |||||||||||
| 67 | =over | ||||||||||
| 68 | |||||||||||
| 69 | =item --argfile I<filename> | ||||||||||
| 70 | |||||||||||
| 71 | The name of a file to read more options from. This can be used more | ||||||||||
| 72 | than once. For example: | ||||||||||
| 73 | |||||||||||
| 74 | --argfile your.args --argfile my.args | ||||||||||
| 75 | |||||||||||
| 76 | See L</Options Files> for more information. | ||||||||||
| 77 | |||||||||||
| 78 | =item --bak | ||||||||||
| 79 | |||||||||||
| 80 | --bak I<string> | ||||||||||
| 81 | |||||||||||
| 82 | If the input file/files is/are being overwritten (--overwrite is on), copy | ||||||||||
| 83 | the original file to "I<filename>.I<string>". If the value is empty, there | ||||||||||
| 84 | is no backup file written. | ||||||||||
| 85 | (default:org) | ||||||||||
| 86 | |||||||||||
| 87 | =item --debug | ||||||||||
| 88 | |||||||||||
| 89 | Enable verbose debugging output. Used for debugging this module; | ||||||||||
| 90 | in other words, don't bother. | ||||||||||
| 91 | (default:off) | ||||||||||
| 92 | |||||||||||
| 93 | =item --entrysep | ||||||||||
| 94 | |||||||||||
| 95 | --entrysep I<string> | ||||||||||
| 96 | |||||||||||
| 97 | Separator string for non-<li> item entries | ||||||||||
| 98 | (default: ", ") | ||||||||||
| 99 | |||||||||||
| 100 | =item --footer | ||||||||||
| 101 | |||||||||||
| 102 | --footer I<file> | ||||||||||
| 103 | |||||||||||
| 104 | File containing footer text for table of contents. | ||||||||||
| 105 | |||||||||||
| 106 | =item --header | ||||||||||
| 107 | |||||||||||
| 108 | --header I<file> | ||||||||||
| 109 | |||||||||||
| 110 | File containing header text for table of contents. | ||||||||||
| 111 | |||||||||||
| 112 | =item --help | ||||||||||
| 113 | |||||||||||
| 114 | Print a short help message and exit. | ||||||||||
| 115 | |||||||||||
| 116 | =item --ignore_only_one | ||||||||||
| 117 | |||||||||||
| 118 | If there would be only one item in the ToC, don't make a ToC. | ||||||||||
| 119 | |||||||||||
| 120 | =item --ignore_sole_first | ||||||||||
| 121 | |||||||||||
| 122 | If the first item in the ToC is of the highest level, | ||||||||||
| 123 | AND it is the only one of that level, ignore it. | ||||||||||
| 124 | This is useful in web-pages where there is only one H1 header | ||||||||||
| 125 | but one doesn't know beforehand whether there will be only one. | ||||||||||
| 126 | |||||||||||
| 127 | =item --inline | ||||||||||
| 128 | |||||||||||
| 129 | Put ToC in document at a given point. | ||||||||||
| 130 | See L<Inlining the ToC> for more information. | ||||||||||
| 131 | |||||||||||
| 132 | =item --make_anchors | --gen_anchors | ||||||||||
| 133 | |||||||||||
| 134 | Create anchors for the table-of-contents to link to. | ||||||||||
| 135 | |||||||||||
| 136 | =item --make_toc | --gen_toc | ||||||||||
| 137 | |||||||||||
| 138 | Make a Table-of-Contents which links to anchored significant elements. | ||||||||||
| 139 | |||||||||||
| 140 | =item --man_help | --manpage | --man | ||||||||||
| 141 | |||||||||||
| 142 | Print all documentation and exit. | ||||||||||
| 143 | |||||||||||
| 144 | =item --notoc_match | ||||||||||
| 145 | |||||||||||
| 146 | --notoc_match I<string> | ||||||||||
| 147 | |||||||||||
| 148 | If there are certain individual tags you don't wish to include in the | ||||||||||
| 149 | table of contents, even though they match the "significant elements", | ||||||||||
| 150 | then if this pattern matches contents inside the tag (not the body), | ||||||||||
| 151 | then that tag will not be included, either in generating anchors nor in | ||||||||||
| 152 | generating the ToC. (default: class="notoc") | ||||||||||
| 153 | |||||||||||
| 154 | =item --ol | --nool | ||||||||||
| 155 | |||||||||||
| 156 | Use an ordered list for Table-of-Contents entries (to a given depth). | ||||||||||
| 157 | If --ol is false (i.e. --nool is set) then I<don't> use an ordered list | ||||||||||
| 158 | for ToC entries. | ||||||||||
| 159 | |||||||||||
| 160 | (default:false) | ||||||||||
| 161 | |||||||||||
| 162 | (See --ol_num_levels to determine how deep the ordered-list listing goes) | ||||||||||
| 163 | |||||||||||
| 164 | =item --ol_num_levels | ||||||||||
| 165 | |||||||||||
| 166 | The number of levels deep the OL listing will go if --ol is true. | ||||||||||
| 167 | If set to zero, will use an ordered list for all levels. | ||||||||||
| 168 | (default:1) | ||||||||||
| 169 | |||||||||||
| 170 | =item --outfile | ||||||||||
| 171 | |||||||||||
| 172 | --outfile I<file> | ||||||||||
| 173 | |||||||||||
| 174 | File to write the output to. This is where the modified HTML output and | ||||||||||
| 175 | the Table-of-Contents goes to. If you give '-' as the filename, then | ||||||||||
| 176 | output will go to STDOUT. (default: STDOUT) | ||||||||||
| 177 | |||||||||||
| 178 | =item --overwrite | ||||||||||
| 179 | |||||||||||
| 180 | Overwrite the input file with the output. If this is in effect, --outfile | ||||||||||
| 181 | is ignored. Used in I<generate_anchors> for creating the | ||||||||||
| 182 | anchors "in place" and in I<generate_toc> if the --inline option is in | ||||||||||
| 183 | effect. (default:off) | ||||||||||
| 184 | |||||||||||
| 185 | =item --quiet | ||||||||||
| 186 | |||||||||||
| 187 | Suppress informative messages. (default: off) | ||||||||||
| 188 | |||||||||||
| 189 | =item --textonly | ||||||||||
| 190 | |||||||||||
| 191 | Use only text content in significant elements. | ||||||||||
| 192 | |||||||||||
| 193 | =item --title | ||||||||||
| 194 | |||||||||||
| 195 | --title I<string> | ||||||||||
| 196 | |||||||||||
| 197 | Title for ToC page (if not using --header or --inline or --toc_only) | ||||||||||
| 198 | (default: "Table of Contents") | ||||||||||
| 199 | |||||||||||
| 200 | =item --toc_after | ||||||||||
| 201 | |||||||||||
| 202 | --toc_after I<tag>=I<suffix> | ||||||||||
| 203 | |||||||||||
| 204 | --toc_after "H2=</em>" | ||||||||||
| 205 | |||||||||||
| 206 | For defining layout of significant elements in the ToC. The I<tag> is | ||||||||||
| 207 | the HTML tag which marks the start of the element. The I<suffix> is | ||||||||||
| 208 | what is required to be appended to the Table of Contents entry generated | ||||||||||
| 209 | for that tag. This is a cumulative hash argument. (default: undefined) | ||||||||||
| 210 | |||||||||||
| 211 | =item --toc_before | ||||||||||
| 212 | |||||||||||
| 213 | --toc_before I<tag>=I<prefix> | ||||||||||
| 214 | |||||||||||
| 215 | --toc_before "H2=<em>" | ||||||||||
| 216 | |||||||||||
| 217 | For defining the layout of significant elements in the ToC. The I<tag> | ||||||||||
| 218 | is the HTML tag which marks the start of the element. The I<prefix> is | ||||||||||
| 219 | what is required to be prepended to the Table of Contents entry | ||||||||||
| 220 | generated for that tag. This is a cumulative hash argument. (default: | ||||||||||
| 221 | undefined) | ||||||||||
| 222 | |||||||||||
| 223 | =item --toc_end | ||||||||||
| 224 | |||||||||||
| 225 | --toc_end I<tag>=I<endtag> | ||||||||||
| 226 | |||||||||||
| 227 | --toc_end "H1=/H1" | ||||||||||
| 228 | |||||||||||
| 229 | For defining significant elements. The I<tag> is the HTML tag which | ||||||||||
| 230 | marks the start of the element. The I<endtag> the HTML tag which | ||||||||||
| 231 | marks the end of the element. When matching in the input file, case | ||||||||||
| 232 | is ignored (but make sure that all your I<tag> options referring to the same | ||||||||||
| 233 | tag are exactly the same!). This is a cumulative hash argument. | ||||||||||
| 234 | (default: H1=/H1 H2=/H2) | ||||||||||
| 235 | |||||||||||
| 236 | =item --toc_entry | ||||||||||
| 237 | |||||||||||
| 238 | --toc_entry I<tag>=I<level> | ||||||||||
| 239 | |||||||||||
| 240 | --toc_entry "TITLE=1" --toc_entry "H1=2" | ||||||||||
| 241 | |||||||||||
| 242 | For defining significant elements. The I<tag> is the HTML tag which marks | ||||||||||
| 243 | the start of the element. The I<level> is what level the tag is considered | ||||||||||
| 244 | to be. The value of I<level> must be numeric, and non-zero. If the value | ||||||||||
| 245 | is negative, consective entries represented by the significant_element will | ||||||||||
| 246 | be separated by the value set by --entrysep option. | ||||||||||
| 247 | This is a cumulative hash argument. | ||||||||||
| 248 | (default: H1=1 H2=2) | ||||||||||
| 249 | |||||||||||
| 250 | =item --toc_label | --toclabel | ||||||||||
| 251 | |||||||||||
| 252 | --toc_label I<string> | ||||||||||
| 253 | |||||||||||
| 254 | HTML text that labels the ToC. Always used. | ||||||||||
| 255 | (default: "<h1>Table of Contents</h1>") | ||||||||||
| 256 | |||||||||||
| 257 | =item --toc_only | --notoc_only | ||||||||||
| 258 | |||||||||||
| 259 | Output only the Table of Contents, that is, the Table of Contents plus | ||||||||||
| 260 | the toc_label. If there is a --header or a --footer, these will also be | ||||||||||
| 261 | output. | ||||||||||
| 262 | |||||||||||
| 263 | If --toc_only is false (i.e. --notoc_only is set) then if there is no | ||||||||||
| 264 | --header, and --inline is not true, then a suitable HTML page header will | ||||||||||
| 265 | be output, and if there is no --footer and --inline is not true, | ||||||||||
| 266 | then a HTML page footer will be output. | ||||||||||
| 267 | (default:--notoc_only) | ||||||||||
| 268 | |||||||||||
| 269 | =item --toc_tag | ||||||||||
| 270 | |||||||||||
| 271 | --toc_tag I<string> | ||||||||||
| 272 | |||||||||||
| 273 | If a ToC is to be included inline, this is the pattern which is used to | ||||||||||
| 274 | match the tag where the ToC should be put. This can be a start-tag, an | ||||||||||
| 275 | end-tag or a comment, but the E<lt> should be left out; that is, if you | ||||||||||
| 276 | want the ToC to be placed after the BODY tag, then give "BODY". If you | ||||||||||
| 277 | want a special comment tag to make where the ToC should go, then include | ||||||||||
| 278 | the comment marks, for example: "!--toc--" (default:BODY) | ||||||||||
| 279 | |||||||||||
| 280 | =item --toc_tag_replace | ||||||||||
| 281 | |||||||||||
| 282 | In conjunction with --toc_tag, this is a flag to say whether the given tag | ||||||||||
| 283 | should be replaced, or if the ToC should be put after the tag. | ||||||||||
| 284 | This can be useful if your toc_tag is a comment and you don't need it | ||||||||||
| 285 | after you have the ToC in place. | ||||||||||
| 286 | (default:false) | ||||||||||
| 287 | |||||||||||
| 288 | =item --use_id | ||||||||||
| 289 | |||||||||||
| 290 | Use id="I<name>" for anchors rather than <a name="I<name>"> anchors. | ||||||||||
| 291 | However if an anchor already exists for a Significant Element, this | ||||||||||
| 292 | won't make an ID for that particular element. | ||||||||||
| 293 | |||||||||||
| 294 | =item --useorg | ||||||||||
| 295 | |||||||||||
| 296 | Use pre-existing backup files as the input source; that is, files of the | ||||||||||
| 297 | form I<filename>.I<bak> (see --bak). | ||||||||||
| 298 | |||||||||||
| 299 | =back | ||||||||||
| 300 | |||||||||||
| 301 | =head1 FILE FORMATS | ||||||||||
| 302 | |||||||||||
| 303 | =head2 Options Files | ||||||||||
| 304 | |||||||||||
| 305 | Options can be given in files as well as on the command-line by | ||||||||||
| 306 | using the --argfile I<filename> option in the command-line. | ||||||||||
| 307 | Also, the files ~/.hypertocrc and ./.hypertocrc are checked for options. | ||||||||||
| 308 | |||||||||||
| 309 | The format is as follows: | ||||||||||
| 310 | Lines starting with # are comments. Lines enclosed in PoD markers are | ||||||||||
| 311 | also comments. Blank lines are ignored. The options themselves | ||||||||||
| 312 | should be given the way they would be on the command line, that is, | ||||||||||
| 313 | the option name (I<including> the --) followed by its value (if any). | ||||||||||
| 314 | |||||||||||
| 315 | For example: | ||||||||||
| 316 | |||||||||||
| 317 | # set the ToC to be three-level | ||||||||||
| 318 | --toc_entry H1=1 | ||||||||||
| 319 | --toc_entry H2=2 | ||||||||||
| 320 | --toc_entry H3=3 | ||||||||||
| 321 | |||||||||||
| 322 | --toc_end H1=/H1 | ||||||||||
| 323 | --toc_end H2=/H2 | ||||||||||
| 324 | --toc_end H3=/H3 | ||||||||||
| 325 | |||||||||||
| 326 | Option files can be nested, by giving an --argfile I<filename> | ||||||||||
| 327 | argument inside the option file, it will go and get that referred | ||||||||||
| 328 | file as well. | ||||||||||
| 329 | |||||||||||
| 330 | See L<Getopt::ArgvFile> for more information. | ||||||||||
| 331 | |||||||||||
| 332 | =head1 DETAILS | ||||||||||
| 333 | |||||||||||
| 334 | =head2 Significant Elements | ||||||||||
| 335 | |||||||||||
| 336 | Here are some examples of defining the significant elements for your | ||||||||||
| 337 | Table of Contents. | ||||||||||
| 338 | |||||||||||
| 339 | =head3 Example of Default | ||||||||||
| 340 | |||||||||||
| 341 | The following reflects the default setting if nothing is explicitly | ||||||||||
| 342 | specified: | ||||||||||
| 343 | |||||||||||
| 344 | --toc_entry "H1=1" --toc_end "H1=/H1" --toc_entry "H2=2" --toc_end "H2=/H2" | ||||||||||
| 345 | |||||||||||
| 346 | Or, if it was defined in one of the possible L</Options Files>: | ||||||||||
| 347 | |||||||||||
| 348 | # default settings | ||||||||||
| 349 | --toc_entry H1=1 | ||||||||||
| 350 | --toc_end H1=/H1 | ||||||||||
| 351 | --toc_entry H2=2 | ||||||||||
| 352 | --toc_end H2=/H2 | ||||||||||
| 353 | |||||||||||
| 354 | =head3 Example of before/after | ||||||||||
| 355 | |||||||||||
| 356 | The following options make use of the before/after options: | ||||||||||
| 357 | |||||||||||
| 358 | # An options file that adds some formatting | ||||||||||
| 359 | # make level 1 ToC entries <strong> | ||||||||||
| 360 | --toc_entry H1=1 | ||||||||||
| 361 | --toc_end H1=/H1 | ||||||||||
| 362 | --toc_before H1=<strong> | ||||||||||
| 363 | --toc_after H1=</strong> | ||||||||||
| 364 | |||||||||||
| 365 | # make level 2 ToC entries <em> | ||||||||||
| 366 | --toc_entry H2=2 | ||||||||||
| 367 | --toc_end H2=/H2 | ||||||||||
| 368 | --toc_before H2=<em> | ||||||||||
| 369 | --toc_after H2=</em> | ||||||||||
| 370 | |||||||||||
| 371 | # Make level 3 entries as is | ||||||||||
| 372 | --toc_entry H3=3 | ||||||||||
| 373 | --toc_end H3=/H3 | ||||||||||
| 374 | |||||||||||
| 375 | =head3 Example of custom end | ||||||||||
| 376 | |||||||||||
| 377 | The following options try to index definition terms: | ||||||||||
| 378 | |||||||||||
| 379 | # An options file that can work for Glossary type documents | ||||||||||
| 380 | --toc_entry H1=1 | ||||||||||
| 381 | --toc_end H1=/H1 | ||||||||||
| 382 | --toc_entry H2=2 | ||||||||||
| 383 | --toc_end H2=/H2 | ||||||||||
| 384 | |||||||||||
| 385 | # Assumes document has a DD for each DT, otherwise ToC | ||||||||||
| 386 | # will get entries with alot of text. | ||||||||||
| 387 | --toc_entry DT=3 | ||||||||||
| 388 | --toc_end DT=DD | ||||||||||
| 389 | --toc_before DT=<em> | ||||||||||
| 390 | --toc_after DT=</em> | ||||||||||
| 391 | |||||||||||
| 392 | =head2 Formatting the ToC | ||||||||||
| 393 | |||||||||||
| 394 | The --toc_entry etc. options give you control on how the ToC entries may | ||||||||||
| 395 | look, but there are other options to affect the final appearance of the | ||||||||||
| 396 | ToC file created. | ||||||||||
| 397 | |||||||||||
| 398 | With the --header option, the contents of the given file will be prepended | ||||||||||
| 399 | before the generated ToC. This allows you to have introductory text, | ||||||||||
| 400 | or any other text, before the ToC. | ||||||||||
| 401 | |||||||||||
| 402 | =over | ||||||||||
| 403 | |||||||||||
| 404 | =item Note: | ||||||||||
| 405 | |||||||||||
| 406 | If you use the --header option, make sure the file specified | ||||||||||
| 407 | contains the opening HTML tag, the HEAD element (containing the | ||||||||||
| 408 | TITLE element), and the opening BODY tag. However, these | ||||||||||
| 409 | tags/elements should not be in the header file if the --inline | ||||||||||
| 410 | options is used. See L</Inlining the ToC> for information on what | ||||||||||
| 411 | the header file should contain for inlining the ToC. | ||||||||||
| 412 | |||||||||||
| 413 | =back | ||||||||||
| 414 | |||||||||||
| 415 | With the --toc_label option, the contents of the given string will be | ||||||||||
| 416 | prepended before the generated ToC (but after any text taken from a | ||||||||||
| 417 | --header file). | ||||||||||
| 418 | |||||||||||
| 419 | With the --footer option, the contents of the file will be appended | ||||||||||
| 420 | after the generated ToC. | ||||||||||
| 421 | |||||||||||
| 422 | =over | ||||||||||
| 423 | |||||||||||
| 424 | =item Note: | ||||||||||
| 425 | |||||||||||
| 426 | If you use the -footer, make sure it includes the closing BODY | ||||||||||
| 427 | and HTML tags (unless, of course, you are using the --inline option). | ||||||||||
| 428 | |||||||||||
| 429 | =back | ||||||||||
| 430 | |||||||||||
| 431 | If the --header option is not specified, the appropriate starting | ||||||||||
| 432 | HTML markup will be added, unless the --toc_only option is specified. | ||||||||||
| 433 | If the --footer option is not specified, the appropriate closing | ||||||||||
| 434 | HTML markup will be added, unless the --toc_only option is specified. | ||||||||||
| 435 | |||||||||||
| 436 | If you do not want/need to deal with header, and footer, files, then | ||||||||||
| 437 | you are alloed to specify the title, --title option, of the ToC file; | ||||||||||
| 438 | and it allows you to specify a heading, or label, to put before ToC | ||||||||||
| 439 | entries' list, the --toc_label option. Both options have default values, | ||||||||||
| 440 | see L</OPTIONS> for more information on each option. | ||||||||||
| 441 | |||||||||||
| 442 | If you do not want HTML page tags to be supplied, and just want | ||||||||||
| 443 | the ToC itself, then specify the --toc_only option. | ||||||||||
| 444 | If there are no --header or --footer files, then this will simply | ||||||||||
| 445 | output the contents of --toc_label and the ToC itself. | ||||||||||
| 446 | |||||||||||
| 447 | =head2 Inlining the ToC | ||||||||||
| 448 | |||||||||||
| 449 | The ability to incorporate the ToC directly into an HTML document | ||||||||||
| 450 | is supported via the --inline option. | ||||||||||
| 451 | |||||||||||
| 452 | Inlining will be done on the first file in the list of files processed, | ||||||||||
| 453 | and will only be done if that file contains an opening tag matching the | ||||||||||
| 454 | --toc_tag value. | ||||||||||
| 455 | |||||||||||
| 456 | If --overwrite is true, then the first file in the list will be | ||||||||||
| 457 | overwritten, with the generated ToC inserted at the appropriate spot. | ||||||||||
| 458 | Otherwise a modified version of the first file is output to either STDOUT | ||||||||||
| 459 | or to the output file defined by the --outfile option. | ||||||||||
| 460 | |||||||||||
| 461 | The options --toc_tag and --toc_tag_replace are used to determine where | ||||||||||
| 462 | and how the ToC is inserted into the output. | ||||||||||
| 463 | |||||||||||
| 464 | =head3 Example 1 | ||||||||||
| 465 | |||||||||||
| 466 | # this is the default | ||||||||||
| 467 | --toc_tag BODY --notoc_tag_replace | ||||||||||
| 468 | |||||||||||
| 469 | This will put the generated ToC after the BODY tag of the first file. | ||||||||||
| 470 | If the --header option is specified, then the contents of the specified | ||||||||||
| 471 | file are inserted after the BODY tag. If the --toc_label option is not | ||||||||||
| 472 | empty, then the text specified by the --toc_label option is inserted. | ||||||||||
| 473 | Then the ToC is inserted, and finally, if the --footer option is | ||||||||||
| 474 | specified, it inserts the footer. Then the rest of the input file | ||||||||||
| 475 | follows as it was before. | ||||||||||
| 476 | |||||||||||
| 477 | =head3 Example 2 | ||||||||||
| 478 | |||||||||||
| 479 | --toc_tag '!--toc--' --toc_tag_replace | ||||||||||
| 480 | |||||||||||
| 481 | This will put the generated ToC after the first comment of the form | ||||||||||
| 482 | <!--toc-->, and that comment will be replaced by the ToC | ||||||||||
| 483 | (in the order | ||||||||||
| 484 | --header | ||||||||||
| 485 | --toc_label | ||||||||||
| 486 | ToC | ||||||||||
| 487 | --footer) | ||||||||||
| 488 | followed by the rest of the input file. | ||||||||||
| 489 | |||||||||||
| 490 | =over | ||||||||||
| 491 | |||||||||||
| 492 | =item Note: | ||||||||||
| 493 | |||||||||||
| 494 | The header file should not contain the beginning HTML tag | ||||||||||
| 495 | and HEAD element since the HTML file being processed should | ||||||||||
| 496 | already contain these tags/elements. | ||||||||||
| 497 | |||||||||||
| 498 | =back | ||||||||||
| 499 | |||||||||||
| 500 | =head1 EXAMPLES | ||||||||||
| 501 | |||||||||||
| 502 | =head2 Create an inline ToC for one file | ||||||||||
| 503 | |||||||||||
| 504 | hypertoc --inline --make_anchors --overwrite --make_toc index.html | ||||||||||
| 505 | |||||||||||
| 506 | This will create anchors in C<index.html>, create a ToC with | ||||||||||
| 507 | a heading of "Table of Contents" and place it after the BODY | ||||||||||
| 508 | tag of C<index.html>. The file index.html.org will contain | ||||||||||
| 509 | the original index.html file, without ToC or anchors. | ||||||||||
| 510 | |||||||||||
| 511 | =head2 Create a ToC file from multiple files | ||||||||||
| 512 | |||||||||||
| 513 | First, create the anchors. | ||||||||||
| 514 | |||||||||||
| 515 | hypertoc --make_anchors --overwrite index.html fred.html george.html | ||||||||||
| 516 | |||||||||||
| 517 | Then create the ToC | ||||||||||
| 518 | |||||||||||
| 519 | hypertoc --make_toc --outfile table.html index.html fred.html george.html | ||||||||||
| 520 | |||||||||||
| 521 | =head2 Create an inline ToC after the first heading of the first file | ||||||||||
| 522 | |||||||||||
| 523 | hypertoc --make_anchors --inline --overwrite --make_toc --toc_tag /H1 \ | ||||||||||
| 524 | --notoc_tag_replace --toc_label "" index.html fred.html george.html | ||||||||||
| 525 | |||||||||||
| 526 | This will create anchors in the C<index.html>, C<fred.html> and | ||||||||||
| 527 | C<george.html> files, create a ToC with no header and place it after the | ||||||||||
| 528 | first H1 header in C<index.html> and back up the original files to | ||||||||||
| 529 | C<index.html.org>, C<fred.html.org> and C<george.html.org> | ||||||||||
| 530 | |||||||||||
| 531 | =head2 Create an inline ToC with custom elements | ||||||||||
| 532 | |||||||||||
| 533 | hypertoc --quiet --make_anchors --bak "" --overwrite \ | ||||||||||
| 534 | --make_toc --inline --toc_label "" --toc_tag '!--toc--' \ | ||||||||||
| 535 | --toc_tag_replace \ | ||||||||||
| 536 | --toc_entry H2=1 --toc_entry H3=2 \ | ||||||||||
| 537 | --toc_end H2=/H2 --toc_end H3=/H3 myfile.html | ||||||||||
| 538 | |||||||||||
| 539 | This will create an inline ToC overwriting the original file, and | ||||||||||
| 540 | replacing a <!--toc--> comment, and which takes H2 headers as level 1 | ||||||||||
| 541 | and H3 headers as level 2. This can be useful where the .html file | ||||||||||
| 542 | is generated by some other process, and you can then create the ToC as | ||||||||||
| 543 | the last step. | ||||||||||
| 544 | |||||||||||
| 545 | =head2 Create a ToC with custom elements | ||||||||||
| 546 | |||||||||||
| 547 | hypertoc --quiet --make_anchors --bak "" --overwrite \ | ||||||||||
| 548 | --toc_entry TITLE=1 --toc_end TITLE=/TITLE | ||||||||||
| 549 | --toc_entry H2=2 --toc_entry H3=3 \ | ||||||||||
| 550 | --toc_end H2=/H2 --toc_end H3=/H3 \ | ||||||||||
| 551 | --make_toc --outfile index.html \ | ||||||||||
| 552 | mary.html fred.html george.html | ||||||||||
| 553 | |||||||||||
| 554 | This creates anchors at the H2 and H3 elements, and creates a ToC file called | ||||||||||
| 555 | index.html, indexing on the TITLE, and the H2 and H3 elements. | ||||||||||
| 556 | |||||||||||
| 557 | =head2 Create a ToC with custom elements and options file | ||||||||||
| 558 | |||||||||||
| 559 | Given an options file called 'custom.opt' as follows: | ||||||||||
| 560 | |||||||||||
| 561 | # Title, H2 and H3 | ||||||||||
| 562 | --toc_entry TITLE=1 | ||||||||||
| 563 | --toc_end TITLE=/TITLE | ||||||||||
| 564 | --toc_entry H2=2 | ||||||||||
| 565 | --toc_end H2=/H2 | ||||||||||
| 566 | --toc_entry H3=3 | ||||||||||
| 567 | --toc_end H3=/H3 | ||||||||||
| 568 | |||||||||||
| 569 | then the previous example can have shorter command lines as follows: | ||||||||||
| 570 | |||||||||||
| 571 | hypertoc --quiet --make_anchors --bak "" --overwrite \ | ||||||||||
| 572 | --argfile custom.opt --make_toc --outfile index.html mary.html fred.html george.html | ||||||||||
| 573 | |||||||||||
| 574 | =head1 NOTES | ||||||||||
| 575 | |||||||||||
| 576 | =over | ||||||||||
| 577 | |||||||||||
| 578 | =item * | ||||||||||
| 579 | |||||||||||
| 580 | hypertoc is smart enough to detect anchors inside significant | ||||||||||
| 581 | elements. If the anchor defines the NAME attribute, hypertoc uses | ||||||||||
| 582 | the value. Else, it adds its own NAME attribute to the anchor. | ||||||||||
| 583 | If --use_id is true, then it likewise checks for and uses IDs. | ||||||||||
| 584 | |||||||||||
| 585 | =item * | ||||||||||
| 586 | |||||||||||
| 587 | The TITLE element is treated specially if specified as a significant element. | ||||||||||
| 588 | It is illegal to insert anchors (A) into TITLE elements. | ||||||||||
| 589 | Therefore, hypertoc will actually link to the filename itself | ||||||||||
| 590 | instead of the TITLE element of the document. | ||||||||||
| 591 | |||||||||||
| 592 | =item * | ||||||||||
| 593 | |||||||||||
| 594 | hypertoc will ignore a significant element if it does not contain | ||||||||||
| 595 | any non-whitespace characters. A warning message is generated if | ||||||||||
| 596 | such a condition exists. | ||||||||||
| 597 | |||||||||||
| 598 | =item * | ||||||||||
| 599 | |||||||||||
| 600 | If you have a sequence of significant elements that change in a slightly | ||||||||||
| 601 | disordered fashion, such as H1 -> H3 -> H2 or even H2 -> H1, though | ||||||||||
| 602 | hypertoc deals with this to create a list which is still good HTML, if | ||||||||||
| 603 | you are using an ordered list to that depth, then you will get strange | ||||||||||
| 604 | numbering, as an extra list element will have been inserted to nest the | ||||||||||
| 605 | elements at the correct level. | ||||||||||
| 606 | |||||||||||
| 607 | For example (H2 -> H1 with --ol_num_levels=1): | ||||||||||
| 608 | |||||||||||
| 609 | 1. | ||||||||||
| 610 | * My H2 Header | ||||||||||
| 611 | 2. My H1 Header | ||||||||||
| 612 | |||||||||||
| 613 | For example (H1 -> H3 -> H2 with --ol_num_levels=0 and H3 also being | ||||||||||
| 614 | significant): | ||||||||||
| 615 | |||||||||||
| 616 | 1. My H1 Header | ||||||||||
| 617 | 1. | ||||||||||
| 618 | 1. My H3 Header | ||||||||||
| 619 | 2. My H2 Header | ||||||||||
| 620 | 2. My Second H1 Header | ||||||||||
| 621 | |||||||||||
| 622 | In cases such as this it may be better not to use the --ol option. | ||||||||||
| 623 | |||||||||||
| 624 | =item * | ||||||||||
| 625 | |||||||||||
| 626 | If one is not using --overwrite when generating anchors, then the | ||||||||||
| 627 | command needs to be done in two passes, in order to give the correct | ||||||||||
| 628 | filenames (the ones with the actual anchors in them) to the ToC | ||||||||||
| 629 | generation part. Otherwise the ToC will have anchors pointing to files | ||||||||||
| 630 | that don't have them. | ||||||||||
| 631 | |||||||||||
| 632 | =item * | ||||||||||
| 633 | |||||||||||
| 634 | When using --inline, care needs to be taken if overwriting -- if | ||||||||||
| 635 | one sets the ToC to be included after a given tag (such as the default | ||||||||||
| 636 | BODY) then if one runs the command repeatedly one could get multiple | ||||||||||
| 637 | ToCs in the same file, one after the other. | ||||||||||
| 638 | |||||||||||
| 639 | =back | ||||||||||
| 640 | |||||||||||
| 641 | =head1 CAVEATS | ||||||||||
| 642 | |||||||||||
| 643 | =over | ||||||||||
| 644 | |||||||||||
| 645 | =item * | ||||||||||
| 646 | |||||||||||
| 647 | Version 3.10 (and above) generates more verbose (SEO-friendly) anchors | ||||||||||
| 648 | than prior versions. Thus anchors generated with earlier versions will | ||||||||||
| 649 | not match version 3.10 anchors. | ||||||||||
| 650 | |||||||||||
| 651 | =item * | ||||||||||
| 652 | |||||||||||
| 653 | Version 3.00 (and above) of hypertoc behaves somewhat differently | ||||||||||
| 654 | than Version 2.x of hypertoc. It is now designed to do everything | ||||||||||
| 655 | in one pass, and has dropped certain options: the --infile option | ||||||||||
| 656 | is no longer used (all filenames are put at the end of the command); | ||||||||||
| 657 | the --toc_file option no longer exists; use the --outfile option | ||||||||||
| 658 | instead; the --tocmap option is no longer supported. | ||||||||||
| 659 | |||||||||||
| 660 | It now generates lower-case tags rather than upper-case ones. | ||||||||||
| 661 | |||||||||||
| 662 | =item * | ||||||||||
| 663 | |||||||||||
| 664 | hypertoc is not very efficient (memory and speed), and can be | ||||||||||
| 665 | slow for large documents. | ||||||||||
| 666 | |||||||||||
| 667 | =item * | ||||||||||
| 668 | |||||||||||
| 669 | Now that generation of anchors and of the ToC are done in one pass, | ||||||||||
| 670 | even more memory is used than was the case before. This is more notable | ||||||||||
| 671 | when processing multiple files, since all files are read into memory | ||||||||||
| 672 | before processing them. | ||||||||||
| 673 | |||||||||||
| 674 | =item * | ||||||||||
| 675 | |||||||||||
| 676 | Invalid markup will be generated if a significant element is | ||||||||||
| 677 | contained inside of an anchor. For example: | ||||||||||
| 678 | |||||||||||
| 679 | <a name="foo"><h1>The FOO command</h1></a> | ||||||||||
| 680 | |||||||||||
| 681 | will be converted to (if h1 is a significant element), | ||||||||||
| 682 | |||||||||||
| 683 | <a name="foo"><h1><a name="The">The</a> FOO command</h1></a> | ||||||||||
| 684 | |||||||||||
| 685 | which is illegal since anchors cannot be nested. | ||||||||||
| 686 | |||||||||||
| 687 | It is better style to put anchor statements within the element to | ||||||||||
| 688 | be anchored. For example, the following is preferred: | ||||||||||
| 689 | |||||||||||
| 690 | <h1><a name="foo">The FOO command</a></h1> | ||||||||||
| 691 | |||||||||||
| 692 | hypertoc will detect the "foo" NAME and use it. | ||||||||||
| 693 | |||||||||||
| 694 | Even better is to use IDs: | ||||||||||
| 695 | |||||||||||
| 696 | <h1 id="foo">The FOO command</h1> | ||||||||||
| 697 | |||||||||||
| 698 | =item * | ||||||||||
| 699 | |||||||||||
| 700 | NAME attributes without quotes are not recognized. | ||||||||||
| 701 | |||||||||||
| 702 | =back | ||||||||||
| 703 | |||||||||||
| 704 | =head1 BUGS | ||||||||||
| 705 | |||||||||||
| 706 | Tell me about them. | ||||||||||
| 707 | |||||||||||
| 708 | =head1 REQUIRES | ||||||||||
| 709 | |||||||||||
| 710 | Getopt::Long | ||||||||||
| 711 | Getopt::ArgvFile | ||||||||||
| 712 | File::Basename | ||||||||||
| 713 | Pod::Usage | ||||||||||
| 714 | HTML::LinkList | ||||||||||
| 715 | HTML::Entities | ||||||||||
| 716 | HTML::GenToc | ||||||||||
| 717 | |||||||||||
| 718 | =head1 SCRIPT CATEGORIES | ||||||||||
| 719 | |||||||||||
| 720 | Web | ||||||||||
| 721 | |||||||||||
| 722 | =head1 ENVIRONMENT | ||||||||||
| 723 | |||||||||||
| 724 | =over | ||||||||||
| 725 | |||||||||||
| 726 | =item HOME | ||||||||||
| 727 | |||||||||||
| 728 | hypertoc looks in the HOME directory for config files. | ||||||||||
| 729 | |||||||||||
| 730 | =back | ||||||||||
| 731 | |||||||||||
| 732 | =head1 FILES | ||||||||||
| 733 | |||||||||||
| 734 | =over | ||||||||||
| 735 | |||||||||||
| 736 | =item C<~/.hypertocrc> | ||||||||||
| 737 | |||||||||||
| 738 | User configuration file. | ||||||||||
| 739 | |||||||||||
| 740 | =item C<.hypertocrc> | ||||||||||
| 741 | |||||||||||
| 742 | Configuration file in the current working directory; overrides | ||||||||||
| 743 | options in C<~/.hypertocrc> and is overridden by command-line options. | ||||||||||
| 744 | |||||||||||
| 745 | =back | ||||||||||
| 746 | |||||||||||
| 747 | =head1 SEE ALSO | ||||||||||
| 748 | |||||||||||
| 749 | perl(1) | ||||||||||
| 750 | htmltoc(1) | ||||||||||
| 751 | HTML::GenToc | ||||||||||
| 752 | Getopt::ArgvFile | ||||||||||
| 753 | Getopt::Long | ||||||||||
| 754 | |||||||||||
| 755 | =head1 AUTHOR | ||||||||||
| 756 | |||||||||||
| 757 | Kathryn Andersen http://www.katspace.org/tools/hypertoc/ | ||||||||||
| 758 | |||||||||||
| 759 | Based on htmltoc by Earl Hood ehood AT medusa.acs.uci.edu | ||||||||||
| 760 | |||||||||||
| 761 | Contributions from Dan Dascalescu, <http://dandascalescu.com> | ||||||||||
| 762 | |||||||||||
| 763 | =head1 COPYRIGHT | ||||||||||
| 764 | |||||||||||
| 765 | Copyright (C) 1994-1997 Earl Hood, ehood AT medusa.acs.uci.edu | ||||||||||
| 766 | Copyright (C) 2002-2008 Kathryn Andersen | ||||||||||
| 767 | |||||||||||
| 768 | This program is free software; you can redistribute it and/or modify | ||||||||||
| 769 | it under the terms of the GNU General Public License as published by | ||||||||||
| 770 | the Free Software Foundation; either version 2 of the License, or | ||||||||||
| 771 | (at your option) any later version. | ||||||||||
| 772 | |||||||||||
| 773 | This program is distributed in the hope that it will be useful, | ||||||||||
| 774 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||||||||
| 775 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||||||||
| 776 | GNU General Public License for more details. | ||||||||||
| 777 | |||||||||||
| 778 | You should have received a copy of the GNU General Public License | ||||||||||
| 779 | along with this program; if not, write to the Free Software | ||||||||||
| 780 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||||||||||
| 781 | |||||||||||
| 782 | =cut | ||||||||||
| 783 | |||||||||||
| 784 | ################################################################# | ||||||||||
| 785 | # Includes | ||||||||||
| 786 | 4 | ▶ | use Getopt::Long 2.34; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 787 | 4 | ▶ | use Pod::Usage; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 788 | 4 | ▶ | use File::Basename; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 789 | 4 | ▶ | use HTML::GenToc; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 790 | |||||||||||
| 791 | ################################################################# | ||||||||||
| 792 | # Subroutines | ||||||||||
| 793 | |||||||||||
| 794 | 4 | ▶ | sub init_data ($) { | ||||||||
|
Subroutine
init_data: called CC=1 SCAR=0.0
| |||||||||||
| 795 | 4 | my $data_ref = shift; | |||||||||
| 796 | |||||||||||
| 797 | 4 | my %args = (); | |||||||||
| 798 | 4 | $args{manpage} = 0; | |||||||||
| 799 | 4 | $args{debug} = 0; | |||||||||
| 800 | 4 | $args{quiet} = 0; | |||||||||
| 801 | |||||||||||
| 802 | 4 | $data_ref->{args} = \%args; | |||||||||
| 803 | } | ||||||||||
| 804 | |||||||||||
| 805 | 4 | ▶ | sub process_args ($) { | ||||||||
|
Subroutine
process_args: called CC=4 SCAR=15.0
| |||||||||||
| 806 | 4 | my $data_ref = shift; | |||||||||
| 807 | 4 | my $args_ref = $data_ref->{args}; | |||||||||
| 808 | |||||||||||
| 809 | 4 | my $ok = 1; | |||||||||
| 810 | |||||||||||
| 811 | # check the rc file if we can | ||||||||||
| 812 | 4 | ▶ | if (eval("require Getopt::ArgvFile")) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 813 | my $nameBuilder=sub | ||||||||||
| 814 | 0 | ▶ | { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 815 | 0 | my $bn = basename($_[0], ''); | |||||||||
| 816 | 0 | [".${bn}rc", ".${bn}/config", ".config/${bn}/config"]; | |||||||||
| 817 | 0 | }; | |||||||||
| 818 | 0 | Getopt::ArgvFile::argvFile( | |||||||||
| 819 | startupFilename=>$nameBuilder, | ||||||||||
| 820 | fileOption=>'argfile', | ||||||||||
| 821 | home=>1, | ||||||||||
| 822 | current=>1); | ||||||||||
| 823 | } | ||||||||||
| 824 | 4 | my $op = new Getopt::Long::Parser; | |||||||||
| 825 | 4 | $op->configure(qw(auto_version auto_help)); | |||||||||
| 826 | 4 | $op->getoptions($args_ref, | |||||||||
| 827 | 'manpage|man_help', | ||||||||||
| 828 | 'debug', | ||||||||||
| 829 | 'quiet!', | ||||||||||
| 830 | 'bak=s', | ||||||||||
| 831 | 'entrysep=s', | ||||||||||
| 832 | 'footer=s', | ||||||||||
| 833 | 'ignore_sole_first!', | ||||||||||
| 834 | 'inline!', | ||||||||||
| 835 | 'header=s', | ||||||||||
| 836 | 'notoc_match=s', | ||||||||||
| 837 | 'ol|ordered_list!', | ||||||||||
| 838 | 'ol_num_levels=n', | ||||||||||
| 839 | 'overwrite!', | ||||||||||
| 840 | 'textonly!', | ||||||||||
| 841 | 'title=s', | ||||||||||
| 842 | 'toclabel|toc_label=s', | ||||||||||
| 843 | 'tocmap=s', | ||||||||||
| 844 | 'outfile|toc_file|tocfile=s', | ||||||||||
| 845 | 'toc_tag|toctag=s', | ||||||||||
| 846 | 'toc_tag_replace!', | ||||||||||
| 847 | 'toc_only!', | ||||||||||
| 848 | 'toc_entry=s%', | ||||||||||
| 849 | 'toc_end=s%', | ||||||||||
| 850 | 'toc_before=s%', | ||||||||||
| 851 | 'toc_after=s%', | ||||||||||
| 852 | 'use_id!', | ||||||||||
| 853 | 'useorg!', | ||||||||||
| 854 | 'make_toc|gen_toc|generate_toc', | ||||||||||
| 855 | 'make_anchors|gen_anchors|generate_anchors', | ||||||||||
| 856 | ); | ||||||||||
| 857 | 4 | ▶ | if (!$ok) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 858 | { | ||||||||||
| 859 | 0 | pod2usage({ -message => "$0", | |||||||||
| 860 | -exitval => 1, | ||||||||||
| 861 | -verbose => 0, | ||||||||||
| 862 | }); | ||||||||||
| 863 | } | ||||||||||
| 864 | |||||||||||
| 865 | 4 | ▶ | if ($args_ref->{'manpage'}) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 866 | { | ||||||||||
| 867 | 0 | pod2usage({ -message => "$0", | |||||||||
| 868 | -exitval => 0, | ||||||||||
| 869 | -verbose => 2, | ||||||||||
| 870 | }); | ||||||||||
| 871 | } | ||||||||||
| 872 | # transfer script-only things to the data-ref | ||||||||||
| 873 | 4 | $data_ref->{make_anchors} = $args_ref->{make_anchors}; | |||||||||
| 874 | 4 | undef $args_ref->{make_anchors}; | |||||||||
| 875 | 4 | $data_ref->{make_toc} = $args_ref->{make_toc}; | |||||||||
| 876 | 4 | undef $args_ref->{make_toc}; | |||||||||
| 877 | 4 | undef $args_ref->{manpage}; | |||||||||
| 878 | # make the object | ||||||||||
| 879 | 4 | my $toc = HTML::GenToc->new(%{$args_ref}); | |||||||||
| 880 | 4 | $data_ref->{toc} = $toc; | |||||||||
| 881 | } | ||||||||||
| 882 | |||||||||||
| 883 | ################################################################# | ||||||||||
| 884 | # Main | ||||||||||
| 885 | |||||||||||
| 886 | MAIN: { | ||||||||||
| 887 | 4 | my %data = (); | |||||||||
| 888 | 4 | my $result = 0; | |||||||||
| 889 | 4 | init_data(\%data); | |||||||||
| 890 | 4 | process_args(\%data); | |||||||||
| 891 | |||||||||||
| 892 | # Now the remainder must be input-files | ||||||||||
| 893 | 4 | my @infiles = (); | |||||||||
| 894 | 4 | push @infiles, @ARGV; | |||||||||
| 895 | 4 | ▶ | if (!$data{toc}->{quiet}) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 896 | { | ||||||||||
| 897 | 1 | print STDERR "To process: ", join(" ", @infiles), "\n"; | |||||||||
| 898 | } | ||||||||||
| 899 | $result = $data{toc}->generate_toc( | ||||||||||
| 900 | make_anchors=>$data{make_anchors}, | ||||||||||
| 901 | make_toc=>$data{make_toc}, | ||||||||||
| 902 | 4 | input=>\@infiles, | |||||||||
| 903 | ); | ||||||||||
| 904 | 4 | ▶ | if ($result) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 905 | { | ||||||||||
| 906 | 4 | exit 0; | |||||||||
| 907 | } | ||||||||||
| 908 | else | ||||||||||
| 909 | { | ||||||||||
| 910 | 0 | exit 1; | |||||||||
| 911 | } | ||||||||||
| 912 | } | ||||||||||
| 913 | |||||||||||
| 914 | # vim: sw=4 sts=4 ai | ||||||||||