File: htmlpod.pl

package info (click to toggle)
remstats 1.00a4-8woody1
  • links: PTS
  • area: main
  • in suites: woody
  • size: 4,576 kB
  • ctags: 1,020
  • sloc: perl: 11,706; ansic: 2,776; makefile: 944; sh: 869
file content (69 lines) | stat: -rwxr-xr-x 1,370 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!@@PERL@@ @@PERLOPTS@@

# Copyright 1999, 2000, 2001 (c) Thomas Erskine <@@AUTHOR@@>
# See the COPYRIGHT file with the distribution.

# html2pod - roughly translate HTML to POD
# $Id: htmlpod.pl,v 1.4 2001/08/28 15:22:24 remstats Exp $

# - - -   Setup   - - -

my $htmlfile = shift @ARGV;
open (HTML, "<$htmlfile") or die "$0: can't open $htmlfile: $!\n";
my @temp = split('/', $htmlfile);
my $basename = pop @temp;
$basename =~ s/\.[^\.]+$//;
$basename =~ s/\.html$//;

# - - -   Mainline   - - -
my $skipping=1;
while (<HTML>) {
	if ($skipping and /(<body>|<h1>)/i) {
		$skipping = 0;
		print <<"EOD_HEAD";
=cut

TITLE=$basename
DESCRIPTION=
KEYWORDS=$basename
DOCTOP=index
DOCPREV=
DOCNEXT=

=pod

EOD_HEAD
		next;
	}
	next if ($skipping);

	s#^\s*<h(\d)>#=head$1 #ig;
	s#</h\d>##ig;
	s#<ul>#=over 4#ig;
	s#</ul>#=back 4#ig;
	s#<ol>#=over 4#ig;
	s#</ol>#=back 4#ig;
	s#<dl>#=over 4#ig;
	s#</dl>#=back 4#ig;
	s#<dt>#=item #ig;
	s#</dt>##ig;
	s#<dd>#\n#ig;
	s#</dd>##ig;
	s#<li>#=item #ig;
	s#</li>##ig;
	s#</?pre>##ig;
	s#<i>#I<#ig;
	s#</i>#>#ig;
	s#<b>#B<#ig;
	s#</b>#>#ig;
	s#<em>#B<#ig;
	s#</em>#>#ig;
	s#<strong>#B<#ig;
	s#</strong>#>#ig;
	s#<tt>#C<#ig;
	s#</tt>#>#ig;
	s#</?p>#\n#ig;
	s#<hr>#\n\n=for html <HR>\n\n=for text\n-------------------------------------------------------------------\n\n#ig;
	s#<a\s+href="([^"]+)">(.*?)</a>#L<$2|$1>#igm;
	print $_;
}