source: lab.git/misc/removejs.pl

Last change on this file was f1ad96d, checked in by mitty <mitty@…>, 12 years ago
  • remove <script> tags from HTML source

git-svn-id: https://lab.mitty.jp/svn/lab/trunk@133 7d2118f6-f56c-43e7-95a2-4bb3031d96e7

  • Property mode set to 100644
File size: 956 bytes
Line 
1#! /usr/bin/perl -w
2
3use strict;
4use warnings;
5
6my $source = shift @ARGV || die "usage: $0 source.html filtered.html";
7my $dest = shift @ARGV || die "usage: $0 source.html filtered.html";
8if (! -r $source) {
9    die "$0: cannot read $source";
10}
11if (-e $dest) {
12    die "$0: file exists! $dest";
13}
14
15open SOURCE, "<$source";
16open DEST, ">$dest";
17
18binmode(DEST);
19
20my $inscript = 0;
21my $startre = '<script\b[^>]*>';
22my $endre = '</script>';
23
24while (my $line = <SOURCE>) {
25    while ($line =~ /$startre/) {
26        $line =~ /^(.*?)$startre(.*)(\r?\n)$/;
27        if ($inscript == 0) {
28            print DEST "$1";
29        }
30        $inscript++;
31        $line = "$2$3";
32    }
33   
34    while ($line =~ /$endre/) {
35        $line =~ /^(.*?)$endre(.*)(\r?\n)$/;
36        if ($inscript <= 0) {
37            warn "$0: something wrong";
38        }
39        $inscript--;
40        $line = "$2$3";
41    }
42   
43    if ($line && $inscript <= 0) {
44        print DEST $line;
45    }
46}
Note: See TracBrowser for help on using the repository browser.