source: trunk/gsdl/bin/script/convert_toc.pl@ 2860

Last change on this file since 2860 was 2860, checked in by sjboddie, 22 years ago

* empty log message *

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 1.4 KB
Line 
1#! /usr/bin/perl -w
2
3# convert_toc.pl converts old <<TOC>> marked up files to use the new
4# <Section> syntax (suitable for processing by HTMLPlug -description_tags
5
6my $line = "";
7my $foundbody = 0;
8my $level = 0;
9while (defined ($line = <STDIN>)) {
10
11 $line =~ s/[\cJ\cM]+$//;
12 if (!$foundbody) {
13 print STDOUT "$line\n";
14 $foundbody = 1 if ($line =~ /<body/i);
15 next;
16 }
17
18 # sort out the <<I>> image tags
19 $line =~ s/&lt;&lt;I&gt;&gt;\s*(\w+\.(?:png|jpe?g|gif))/<center><img src=\"$1\"><\/center><br>\n/igs;
20
21 if ($line =~ /&lt;&lt;TOC(\d+)&gt;&gt;(.*)/) {
22 my $thislevel = $1;
23 my $title = $2;
24 $title =~ s/<[^>]+>//g;
25 $title =~ s/^\s+//;
26 $title =~ s/\s+$//;
27
28 # print out any tags that were on the line
29 while ($line =~ s/(<[^>]+>)//) {
30 print STDOUT $1;
31 }
32
33 print STDOUT "\n<!--\n";
34
35 if ($thislevel <= $level) {
36 for (my $i = 0; $i < ($level-$thislevel+1); $i++) {
37 print STDOUT "</Section>\n";
38 }
39 }
40 print STDOUT "<Section>\n";
41 print STDOUT " <Description>\n";
42 print STDOUT " <Metadata name=\"Title\">$title</Metadata>\n";
43 print STDOUT " </Description>\n";
44 print STDOUT "-->\n";
45
46 $level = $thislevel;
47
48 } elsif ($line =~ /<\/body>/i) {
49 $line =~ /^(.*?)(<\/body>.*)$/i;
50 print STDOUT $1 if defined $1;
51 print STDOUT "\n<!--\n";
52 for (my $j = 0; $j < $level; $j++) {
53 print STDOUT "</Section>\n";
54 }
55 print STDOUT "-->\n";
56 print STDOUT $2 if defined $2;
57 print STDOUT "\n";
58
59 } else {
60 print STDOUT "$line\n";
61 }
62}
Note: See TracBrowser for help on using the repository browser.