File: wikifytable.pl

package info (click to toggle)
emboss 6.6.0%2Bdfsg-12
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 571,584 kB
  • sloc: ansic: 460,579; java: 29,383; perl: 13,573; sh: 12,753; makefile: 3,294; csh: 706; asm: 351; xml: 239; pascal: 237; modula3: 8
file content (47 lines) | stat: -rwxr-xr-x 1,174 bytes parent folder | download | duplicates (8)
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
#!/usr/bin/perl -w

$text = "";
while (<>) {
    s/<\/[Tt][DdRrHh]>//gosm;
    s/<\/?[Tt][Aa][Bb][Ll][Ee][^>]*>//gosm;
    $text .= $_;
}
@rows = split(/<[Tt][Rr][^>]*>\s*<[Tt][DdHh][^>]*>/osm,$text);

print "{| style=\"background:#ccccff\" border=\"2\"\n";
$i = 0;
foreach $r(@rows) {
    $i++;
    $r =~ s/\n//gosm;
    @items = split(/<[Tt][DdHh][^>]*>/,$r);
    $j = 0;

    $empty=0;
    $caption=0;
    $header=0;
    if($#items < 0){next}
    if($#items == 0){
	if($items[0] =~ /\S+ [\(][^\)]+[\)] \S+$/){$caption=1}
	elsif($items[0] =~ /Associated qualifiers$/){$caption=1}
	elsif($items[0] =~ /General qualifiers$/){$caption=1}
	elsif($items[0] =~ /\S+ associated \S+ qualifiers$/){$caption=1}
	elsif($items[0] =~ /^[\(]none[\)]$/){$empty=1}
	else {next}
    }
    if($r =~ /<[Tt][Hh]/){$header=1}

    print "|-\n";
    foreach $it (@items) {
	$it =~ s/<[Tt][Rr][^>]*>//gosm;
	$it =~ s/^\s+//gosm;
	$it =~ s/\n$//gosm;
	$it =~ s/^[-]/ -/gosm;
	$j++;
	if($caption) {print "!style=\"background:#ffffcc\" colspan=\"5\"|$it\n"}
	elsif($empty) {print "!colspan=\"5\" align=\"left\"|$it\n"}
	elsif($header) {print "!$it\n"}
	else {print "|$it\n"}
    }
}
print "|}\n";