Debian Codegraph @

docs/fix-python-xhtml

raw
1 #!/usr/bin/perl
2 #
3 # Format XHTML generated by pod2html (via tidy) for websites
4 #
5 # Usage: tidy ... pydoc.html | fix-python-xhtml OUTPUT-FILE
6 #
7 # (C) Copyright 2002 Dave Beckett - http://www.dajobe.org/
8 # University of Bristol
9 #
10
11 use strict;
12 use File::Basename;
13
14 my $progname=basename $0;
15
16 my $main_title="Redland RDF Application Framework";
17
18 my $doc_title="Python API Reference";
19
20 die "USAGE: $progname OUTPUT-FILE\n" if @ARGV < 1;
21
22 my($file)=@ARGV;
23
24 my($pod_rdf_rel)=($file =~ m%^pod/RDF/%) ? '../' : '';
25 my($pod_rdf_redland_rel)=($file =~ m%^pod/RDF/Redland/%) ? '' : 'Redland/';
26
27 my $skip_heading=0;
28
29 open(OUT, ">$file") or die "$progname: Cannot create $file - $!\n";
30 print OUT qq{<?xml version="1.0" encoding="iso-8859-1"?>\n};
31 open(IN, "-");
32 while(<IN>) {
33 if(m%<title>(.*?)</title>%) {
34 s%<title>(.*?)</title>%<title>$main_title - $doc_title</title>%;
35 }
36
37 next if /^<link|meta/i;
38
39 # skip the #-commented heading
40 if(!$skip_heading && m%^<p><tt>\#%) {
41 $skip_heading=1;
42 next;
43 } elsif ($skip_heading == 1) {
44 if(m%\#</tt></p>%) {
45 $skip_heading=2;
46 print OUT "<!-- LICENSE HEADING -->\n";
47 }
48 next;
49 }
50
51 # Links to other Python modules, exceptions
52 s%<a href="(Redland|string|sys|exceptions|__builtin__).html[^"]*">(.+?)</a>%$2%g; #"
53 # The horrors of guessing urls in text
54 s%<a href="http://example.(org|com|net)[^"]*">([^<]+)</a>%$2%g; # "
55 s%<a href="http://(?:localhost/r.rdf|foo|bar)[^"]*">([^<]+)</a>%$2%g; # "
56 # Never leave these in web pages
57 s%<a href="file:[^"]+">/[^<]+</a>%%g; # "
58
59 s%RDF.html\#%#%;
60
61 # Bad IDs, who writes this stuff?
62 s%<a name="([^"]+)">%my $a=$1; $a =~ s/\&lt;.*?\&gt;//g; qq{<a id="$a" name="$a">}%ge;
63 s%<a id="([^"]+)" name="[^"]+">%my $a=$1; $a =~ s/\&lt;.*?\&gt;//g; $a =~ s/^-//; $a=~ s/ /-/g; qq{<a id="$a" name="$a">}%ge;
64 s%<a href="#-[^"+]">%<a href="#$1">%g;
65
66 # All the __new__ links are broken
67 s%<a href="\#\w+\-__new__">__new__</a>%__new__%;
68 # This is broken too, dunno why
69 s%<a href="\#\-debug">debug</a>%debug%;
70
71 if(m%^<body.*>%) {
72 print OUT qq{<body>\n\n<h1 style="text-align:center">$main_title - $doc_title</h1>\n\n};
73 next;
74 }
75
76 my $year=1900+(localtime)[5];
77 print OUT <<"EOT" if m%^</body>%;
78 <hr />
79
80 <p>(C) Copyright 2000-$year <a href="http://www.dajobe.org/">Dave Beckett</a>, Copyright 2000-2005 <a href="http://www.bristol.ac.uk/">University of Bristol</a></p>
81
82 EOT
83
84 print OUT;
85 }
86 close(IN);
87 close(OUT);