1 |
wakaba |
1.1 |
package WebHACC::Language::CSSInline; |
2 |
|
|
use strict; |
3 |
|
|
require WebHACC::Language::CSS; |
4 |
|
|
push our @ISA, 'WebHACC::Language::CSS'; |
5 |
|
|
|
6 |
|
|
sub generate_syntax_error_section ($) { |
7 |
|
|
my $self = shift; |
8 |
|
|
|
9 |
|
|
my $out = $self->output; |
10 |
|
|
|
11 |
|
|
$self->result->layer_uncertain ('charset'); |
12 |
|
|
|
13 |
|
|
$out->start_section (role => 'parse-errors'); |
14 |
|
|
$out->start_error_list (role => 'parse-errors'); |
15 |
|
|
$self->result->layer_applicable ('syntax'); |
16 |
|
|
|
17 |
|
|
my $input = $self->input; |
18 |
|
|
my $result = $self->result; |
19 |
|
|
|
20 |
|
|
my $p = $self->get_css_parser (); |
21 |
|
|
$p->init; |
22 |
|
|
$p->{onerror} = sub { |
23 |
|
|
my (%opt) = @_; |
24 |
|
|
if (not defined $opt{value} and defined $opt{token}) { |
25 |
|
|
$opt{value} = Whatpm::CSS::Tokenizer->serialize_token ($opt{token}); |
26 |
|
|
} |
27 |
|
|
$result->add_error (%opt, layer => 'syntax'); |
28 |
|
|
}; |
29 |
|
|
$p->{href} = $input->url; |
30 |
|
|
$p->{base_uri} = $input->{base_uri}; |
31 |
|
|
|
32 |
|
|
# if ($parse_mode eq 'q') { |
33 |
|
|
# $p->{unitless_px} = 1; |
34 |
|
|
# $p->{hashless_color} = 1; |
35 |
|
|
# } |
36 |
|
|
|
37 |
|
|
## TODO: Make $input->{s} a ref. |
38 |
|
|
|
39 |
|
|
my $s = \$input->{s}; |
40 |
|
|
unless ($input->{is_char_string}) { |
41 |
|
|
my $charset; |
42 |
|
|
$self->result->layer_uncertain ('encode'); |
43 |
|
|
require Encode; |
44 |
|
|
if (defined $input->{charset}) {## TODO: IANA->Perl |
45 |
|
|
$charset = $input->{charset}; |
46 |
|
|
$s = \(Encode::decode ($input->{charset}, $$s)); |
47 |
|
|
} else { |
48 |
|
|
## TODO: charset detection |
49 |
|
|
$s = \(Encode::decode ($charset = 'utf-8', $$s)); |
50 |
|
|
} |
51 |
|
|
$self->{source_charset} = $charset; |
52 |
|
|
} |
53 |
|
|
|
54 |
|
|
$self->{structure} = $p->parse_char_string_as_inline ($$s); |
55 |
|
|
|
56 |
|
|
$out->end_error_list (role => 'parse-errors'); |
57 |
|
|
$out->end_section; |
58 |
|
|
} # generate_syntax_error_section |
59 |
|
|
|
60 |
|
|
sub source_charset ($) { |
61 |
|
|
return shift->{source_charset}; |
62 |
|
|
} # source_charset |
63 |
|
|
|
64 |
|
|
1; |