-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathannot.pl
81 lines (71 loc) · 1.19 KB
/
annot.pl
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
#
# Generate html for annotated
# code listings.
#
use strict;
use IPC::Open2;
sub beg {
}
sub end {
}
sub md {
open2(my $out, my $in, "perl tools/Markdown.pl");
print $in shift;
close $in;
my $html = join '', <$out>;
close $out;
return $html;
}
sub line {
my $h = shift;
print "<div class=\"listing\"><div class=\"descr\">";
print md($h->{'d'});
print "</div><div class=\"code\">\n<pre><code>";
print $h->{'c'};
print "</code></pre>\n</div></div>\n";
$h->{'c'} = "";
$h->{'d'} = "";
$h->{'n'}++;
print STDERR "[+] Processed fragment $h->{'n'}\n";
}
sub flush {
my $h = shift;
if ($h->{'d'} and $h->{'c'}) {
line($h);
}
if ($h->{'r'}) {
# print STDERR $h->{'r'};
print md($h->{'r'});
$h->{'r'} = "";
}
}
my ($st, %chunk) = 'r';
while (<>) {
if (/^!code$/) {
flush(\%chunk);
beg() if $st eq 'r';
$st = 'c';
next;
} elsif (/^!descr$/) {
flush(\%chunk);
beg() if $st eq 'r';
$st = 'd';
next;
} elsif (/^!end$/) {
flush(\%chunk);
$st = 'r';
if ($chunk{'d'} or $chunk{'c'}) {
print STDERR "Warning, partial chunk!";
}
end();
next;
}
if ($st eq 'c') {
s/&/&/g;
s/</</g;
s/>/>/g;
s/\t/ /g;
}
$chunk{$st} .= $_;
}
flush(\%chunk);