| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package HTML::Valid; |
|
2
|
|
|
|
|
|
|
require Exporter; |
|
3
|
|
|
|
|
|
|
@ISA = qw(Exporter); |
|
4
|
|
|
|
|
|
|
@EXPORT_OK = qw/sanitize_errors/; |
|
5
|
|
|
|
|
|
|
%EXPORT_TAGS = ( |
|
6
|
|
|
|
|
|
|
all => \@EXPORT_OK, |
|
7
|
|
|
|
|
|
|
); |
|
8
|
6
|
|
|
6
|
|
241140
|
use warnings; |
|
|
6
|
|
|
|
|
41
|
|
|
|
6
|
|
|
|
|
173
|
|
|
9
|
6
|
|
|
6
|
|
29
|
use strict; |
|
|
6
|
|
|
|
|
6
|
|
|
|
6
|
|
|
|
|
120
|
|
|
10
|
6
|
|
|
6
|
|
26
|
use Carp; |
|
|
6
|
|
|
|
|
9
|
|
|
|
6
|
|
|
|
|
367
|
|
|
11
|
6
|
|
|
6
|
|
2130
|
use JSON::Parse 'read_json'; |
|
|
6
|
|
|
|
|
6799
|
|
|
|
6
|
|
|
|
|
3086
|
|
|
12
|
|
|
|
|
|
|
our $VERSION = '0.09'; |
|
13
|
|
|
|
|
|
|
require XSLoader; |
|
14
|
|
|
|
|
|
|
XSLoader::load ('HTML::Valid', $VERSION); |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub new |
|
17
|
|
|
|
|
|
|
{ |
|
18
|
4
|
|
|
4
|
1
|
31719
|
my ($class, %options) = @_; |
|
19
|
4
|
|
|
|
|
569
|
my $htv = html_valid_new (); |
|
20
|
4
|
|
|
|
|
16
|
bless $htv; |
|
21
|
4
|
|
|
|
|
15
|
for my $k (keys %options) { |
|
22
|
5
|
|
|
|
|
17
|
$htv->set_option ($k, $options{$k}); |
|
23
|
|
|
|
|
|
|
} |
|
24
|
4
|
|
|
|
|
17
|
return $htv; |
|
25
|
|
|
|
|
|
|
} |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub read_ok_options |
|
28
|
|
|
|
|
|
|
{ |
|
29
|
3
|
|
|
3
|
0
|
7
|
my $ok_options_file = __FILE__; |
|
30
|
3
|
|
|
|
|
14
|
$ok_options_file =~ s!Valid\.pm$!Valid/ok-options.json!; |
|
31
|
3
|
|
|
|
|
16
|
return read_json ($ok_options_file); |
|
32
|
|
|
|
|
|
|
} |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
my $ok_options; |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub set_option |
|
37
|
|
|
|
|
|
|
{ |
|
38
|
7
|
|
|
7
|
1
|
908
|
my ($htv, $option, $value) = @_; |
|
39
|
7
|
|
|
|
|
24
|
$option =~ s/_/-/g; |
|
40
|
7
|
100
|
|
|
|
20
|
if (! $ok_options) { |
|
41
|
3
|
|
|
|
|
12
|
$ok_options = read_ok_options (); |
|
42
|
|
|
|
|
|
|
} |
|
43
|
7
|
100
|
|
|
|
681
|
if ($ok_options->{$option}) { |
|
44
|
6
|
|
|
|
|
112
|
$htv->set_option_unsafe ($option, $value); |
|
45
|
|
|
|
|
|
|
} |
|
46
|
|
|
|
|
|
|
else { |
|
47
|
1
|
|
|
|
|
14
|
warn "Unknown or disallowed option $option"; |
|
48
|
|
|
|
|
|
|
} |
|
49
|
|
|
|
|
|
|
} |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
# Private, sort the messy errors from HTML Tidy by line number, and |
|
52
|
|
|
|
|
|
|
# remove useless messages. |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub sanitize_errors |
|
55
|
|
|
|
|
|
|
{ |
|
56
|
0
|
|
|
0
|
0
|
|
my ($errors) = @_; |
|
57
|
0
|
|
|
|
|
|
$errors =~ s/Info:.*\n//; |
|
58
|
0
|
|
|
|
|
|
$errors =~ s/(?:No|[0-9]+) warnings?\s*(?:and|or|,) (?:[0-9]+ )?errors? were found(?:\.|!)\n//; |
|
59
|
|
|
|
|
|
|
# $errors =~ s/^.*missing.*doctype.*\n//gi; |
|
60
|
0
|
|
|
|
|
|
$errors =~ s/^\s*$//gsm; |
|
61
|
|
|
|
|
|
|
# $errors =~ s/^[0-9]+ warning.*$//gsm; |
|
62
|
|
|
|
|
|
|
# $errors =~ s/^line ([0-9]+)(.*)/$file:$1: $2/gm; |
|
63
|
0
|
|
|
|
|
|
$errors =~ s/^\n//gsm; |
|
64
|
|
|
|
|
|
|
# Work around disordered line numbering in HTML Tidy. |
|
65
|
0
|
|
|
|
|
|
my @errors = split /\n/, $errors; |
|
66
|
0
|
|
|
|
|
|
my %errors; |
|
67
|
0
|
|
|
|
|
|
for (@errors) { |
|
68
|
0
|
|
|
|
|
|
my $line = $_; |
|
69
|
0
|
|
|
|
|
|
$line =~ s/.*:([0-9]+):[0-9]+:.*$/$1/; |
|
70
|
0
|
|
|
|
|
|
$errors{$_} = $line; |
|
71
|
|
|
|
|
|
|
} |
|
72
|
0
|
|
|
|
|
|
@errors = sort {$errors{$a} <=> $errors{$b}} @errors; |
|
|
0
|
|
|
|
|
|
|
|
73
|
0
|
|
|
|
|
|
$errors = join "\n", @errors; |
|
74
|
0
|
|
|
|
|
|
return $errors . "\n"; |
|
75
|
|
|
|
|
|
|
} |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
1; |