-
Notifications
You must be signed in to change notification settings - Fork 791
Expand file tree
/
Copy pathhtmltrim
More file actions
42 lines (35 loc) · 836 Bytes
/
htmltrim
File metadata and controls
42 lines (35 loc) · 836 Bytes
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
#!/usr/local/bin/perl
#
# Get rid of given block element (typically div) of the given class
# Arnaud Le Hors - lehors@w3.org
# $Id: htmltrim,v 1.4 2006-10-09 18:55:52 ihickson Exp $
$PROGNAME = substr($0, rindex($0, "/") + 1);
if ($#ARGV < 2) {
print "Usage: $PROGNAME element class input output\n";
exit 1;
}
$elem = $ARGV[0];
$class = $ARGV[1];
$input = $ARGV[2];
if ($ARGV[3]) {
$output = $ARGV[3];
} else {
$output = "-";
}
# copy file in memory
sub readfile {
$buf = "";
if (!open(INPUT, $_[0])) {
print STDERR "$PROGNAME Error: Cannot open file: $_[0]\n";
return;
}
while (<INPUT>) {
$buf .= $_;
}
close(INPUT);
}
readfile($input);
$buf =~ s/<$elem[ \t\n]+[^>]*class=["']?$class(>|["' \t\n]+[^>]*>).*?<\/$elem>//sigoe;
open(OUTPUT, "> $output");
print OUTPUT $buf;
close(OUTPUT);