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 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280
|
#!/usr/bin/perl -w
$file = $ARGV[0];
if(!defined($file)) {exit}
$outfile = $file;
$outfile =~ s/ - EMBOSS[.]htm/.wiki/g;
open (OUT, ">/cygdrive/h/wikifix/$outfile") || die "Cannot open '$outfile'";
%author = ("ableasby" => "Bleasby",
"price" => "Rice",
"ilongden" => "Longden",
"mschuster" => "Schuster",
);
%types = ("Ione" => "Short",
# headers on one line "Ihtml" => "",
"Itable" => "Options",
"Usage" => "Example",
"Input" => "Input",
"Output" => "Output",
"History" => "History",
"Comment" => "Comment",
"Isee" => "Seealso"
);
%names = ("Alignformats" => "AlignFormats",
"Assemblyformats" => "AssemblyFormats",
"Codonformats" => "CodonFormats",
"Featformats" => "FeatFormats",
"Ontologyformats" => "OntologyFormats",
"Reportformats" => "ReportFormats",
"Resourceformats" => "ResourceFormats",
"Seqformats" => "SeqFormats",
"Seqfeatformats" => "SeqfeatFormats",
"Taxonformats" => "TaxonFormats",
"Textformats" => "TextFormats",
"Urlformats" => "UrlFormats",
"Variationformats" => "VariationFormats",
"Assemblyinformats" => "AssemblyInFormats",
"Codoninformats" => "CodonInFormats",
"Featinformats" => "FeatInFormats",
"Ontologyinformats" => "OntologyInFormats",
"Resourceinformats" => "ResourceInFormats",
"Seqinformats" => "SeqInFormats",
"Seqfeatinformats" => "SeqfeatInFormats",
"Taxoninformats" => "TaxonInFormats",
"Textinformats" => "TextInFormats",
"Urlinformats" => "UrlInFormats",
"Variationformats" => "VariationFormats",
"Gcfiles" => "GeneticCodeFiles",
"Localfiles" => "LocalFiles",
"Graphicsdevices" => "GraphicsDevices",
"Drcat" => "Drcat",
"Edam" => "Edam",
"Go" => "Go",
"Taxon" => "Taxon",
"Jaspfiles" => "JasparFiles",
"Refiles" => "RebaseFiles",
"Jison-programs" => "JonIsonPrograms",
);
use English;
$text = "";
while (<>) {
s/^[ \t]+//;
$text .= $_;
}
$text =~ s/^.*(<body class=\"mediawiki[^\"]+page-(\S+))/$1/osm; # remove all to start of mediawiki
print STDERR "Page name $2\n";
$text =~ s/^.*<h1 id=\"firstHeading\" class=\"firstHeading\">([^<]+)<\/h1>\n//osm; # remove all to start of mediawiki
print STDERR "Page true name $1\n";
$text =~ s/^.*?\n([^\n]+<span class=\"mw-headline\">)/$1/osm; # remove all to first heading
$text =~ s/<span class=noprint><span style=\"color:#[^\"]+\">//gosm;
$text =~ s/<\/span><\/span>/\n/gosm;
$text =~ s/<\!--\s*NewPP limit report[^>]*>//gosm; # remove biblio comments
$text =~ s/<\!--\s*Saved in parser cache.*//gosm; # remove all from start of google footer
$text =~ s/\s*<span class=\"mw-headline\">([^<]+)<\/span>/$1/gosm; # clean up headings
#header tages removed
$text =~ s/(<\/?[Hh][Tt][Mm][Ll]>)//gosm;
$text =~ s/(<\/?[Bb][Oo][Dd][Yy][^>]*?>)//gosm;
$text =~ s/(<[Aa]\s+name\s*=\s*\"([^\"]+)[^>]+>)[^<]*<\/[Aa]>//gosm;
# phylip doc links
$text =~ s/<[Aa]\s+href\s*=\s*\"([^\/\".]+\.html)[^>]+>([^<]+)<\/[Aa]>/[http:\/\/evolution.genetics.washington.edu\/phylip\/doc\/$1 $2]/gosm;
# other links
$text =~ s/<[Aa]\s+href\s*=\s*\"\/wiki\/([^\"]+)[^>]+>\s*([^<]+)<\/[Aa]>/[[$1| $2]]/gosm;
$text =~ s/<[Aa]\s+href\s*=\s*\"([Hh]?[FfTt][Tt][Pp]:[^\"]+)[^>]+>([^<]+)\s*<\/[Aa]>/[$1 $2]/gosm;
$text =~ s/<[Aa]\s+href\s*=\s*\"([Mm]?[Aa][Ii][Ll][Tt][Oo]:[^\"]+)[^>]+>([^<]+)\s*<\/[Aa]>/[$1 $2]/gosm;
$text =~ s/<[Aa]\s+href\s*=\s*\"([^\"]+)[^>]+>([^<]+)\s*<\/[Aa]>/[[$1| $2]]/gosm;
# headers on one line
$text =~ s/(<[Hh]\d>)\s*\n\s*/$1/gosm;
$text =~ s/\n(<\/[Hh]\d>)/$1/gosm;
# remove CSS divisions
$text =~ s/<\/[Dd][Ii][Vv]>//gosm;
# remove rulers
$text =~ s/<[Hh][Rr]>//gosm;
# header levels to wiki syntax
$text =~ s/<[Hh]1>(.*?)<\/[Hh]1>/==$1==/gosm;
$text =~ s/<[Hh]2>(.*?)<\/[Hh]2>/==$1==/gosm;
$text =~ s/<[Hh]3>(.*?)<\/[Hh]3>/===$1===/gosm;
$text =~ s/<[Hh]4>(.*?)<\/[Hh]4>/====$1====/gosm;
# paragraphs to extra newlines at start
$text =~ s/<[Pp]>/\n/gosm;
# remove table row end markings
$text =~ s/^(<\/[Tt][RrDdHh]>)+\n//gosm;
$text =~ s/<\/[Tt][RrDdHh]>//gosm;
$text =~ s/^(<\/[Cc][Aa][Pp][Tt][Ii][Oo][Nn]>)+\n//gosm;
$text =~ s/<\/[Cc][Aa][Pp][Tt][Ii][Oo][Nn]>//gosm;
# remove end-of-paragraph
$text =~ s/<\/[Pp]>//gosm;
# breaks
$text =~ s/(<\/?[Bb][Rr][^>]*>)/\n/gosm;
# bold text
$text =~ s/(<\/?[Bb][^>]*>)/'''/gosm;
# emphasis = bold
$text =~ s/(<\/?[Ee][Mm]>)/'''/gosm;
# italic
$text =~ s/(<\/?[Ii]>)/''/gosm;
# remove empty newlines after list tags
$text =~ s/(<\/?[Ll][Ii]>)\n/$1/gosm;
$text =~ s/(<\/[Ll][Ii]>)//gosm;
$text =~ s/(<\/?[Dd][DdTt]>)\n/$1/gosm;
$text =~ s/(<\/[Dd][DdTt]>)//gosm;
$text =~ s/([^\n])(<[Tt][HhDd][^>]*>)/$1\n$2/gosm;
# Now process the text line-by-line
$i=0;
$pre = 0;
$head=0;
$blank=0;
$table = 0;
$list = "";
while ($text =~ /.*?\n/gos) {
$t = $MATCH;
if($t =~ s/<[Hh][Ee][Aa][Dd]>//gosm) {$head=1}
if($t =~ s/<\/[Hh][Ee][Aa][Dd]>//gosm) {$head=0;next}
if($t =~ s/<!--#include file="header1.inc" -->//gosm) {$head=1}
if($t =~ s/<!--#include file="header2.inc" -->//gosm) {$head=0;next}
if($head) {next}
if($t =~ s/<\/[Tt][Aa][Bb][Ll][Ee][^>]*>//gosm) {
$table = 0;
print OUT "|}\n";
}
if($t =~ s/<[Tt][Aa][Bb][Ll][Ee]([^>]*)>//gosm) {
$table = 1;
$rest = $1;
$resttext = "";
if($rest =~ /sortable/) {$resttext = " sortable"}
print OUT "\n{| class=\"wikitable$resttext\" style=\"background:#ccccff\" border=\"2\"\n";
}
if($t =~ s/<\/[OoUuDd][Ll]>//gosm) {$list = ""}
if($t =~ s/<[Uu][Ll]>//gosm) {$list = "u";$nlist=0}
if($t =~ s/<[Oo][Ll]>//gosm) {$list = "o";$nlist=0}
if($t =~ s/<[Dd][Ll]>//gosm) {$list = "d";$nlist=0}
if($t =~ s/<[Pp][Rr][Ee]>//gosm) {$pre = 1}
if($t =~ s/<\/[Pp][Rr][Ee]>//gosm) {$pre = 0}
if($t =~ /<[!]--[\#]include file=\"([^\"]+)\" -->/gosm){
$ifile = $1;
if($ifile =~ /inc\/([^.]+)[.]address/){
$aname = $1;
if(defined($author{$aname})){$aname = $author{$aname}}
else {$aname = ucfirst($aname)}
$t = "\{\{:Appinc:Address$aname\}\}\n";
}
elsif($ifile =~ /inc\/target([^.]*)[.]itxt/){
$tgtname = ucfirst($1);
$t = "\{\{:Appinc:Target$tgtname\}\}\n";
}
elsif($ifile =~ /inc\/([^.]+)[.]ihelp/){
$t = "";
}
elsif($ifile =~ /inc\/([^.]+)[.](.*)/){
$name = ucfirst($1);
$type=ucfirst($2);
if(defined($names{$name})){$name = $names{$name}}
if(defined($types{$type})){$type = $types{$type}}
if($type eq "Seealso") {
print OUT "==See also==\n";
}
$t = "\{\{:Appinc:$type$name\}\}\n";
}
}
if(!$pre & $t =~ /^\n$/) {$blank++}
else{$blank=0}
$i++;
if($blank > 1){next}
if($blank == 1 && $list ne ""){next}
# print OUT "$i:";
if($list ne "") {$t =~ s/\n/ /}
if($pre) {print OUT " "}
if($t =~ s/<[Tt][Rr]>//gosm) {
if($table) {
print OUT "|-";
$table = 2;
}
}
if($t =~ s/<[Cc][Aa][Pp][Tt][Ii][Oo][Nn]>//gosm) {
if($table) {
print OUT "|+";
$table = 2;
}
}
if($t =~ s/<[Tt][Hh]([^>]*)>//gosm) {
if($table) {
$rest = $1;
$resttext = "";
if($rest =~ /colspan=\"(\d+)\"/) {
$resttext .= " colspan=\"$1\"";
}
if($rest =~ /class=\"unsortable"/) {
$resttext .= " class=\"unsortable\"";
}
if($rest =~ /background:(#[0-9a-fA-F]+)/) {
$resttext .= " style=\"background:$1\"";
}
if($resttext ne "") {$resttext .= "|"}
print OUT "!$resttext ";
$table = 4;
}
}
if($t =~ s/<[Tt][Dd]>//gosm) {
if($table) {
print OUT "| ";
$table = 3;
}
}
if($t =~ s/<[Ll][Ii]>//gosm) {
if($nlist++){print OUT "\n"}
if($list eq "u") {print OUT "* "}
elsif($list eq "o") {print OUT "# "}
}
if($t =~ s/<[Dd][Tt]>([^<]*)//gosm) {
if($nlist++){print OUT "\n"}
if($list eq "d") {print OUT "; $1"}
}
if($t =~ s/<[Dd][Dd]>//gosm) {
if($nlist++){print OUT "\n"}
if($list eq "d") {print OUT ": "}
}
if($nlist && $list eq "") {print OUT "\n";$nlist=0;}
print OUT "$t";
}
|