17 |
}; |
}; |
18 |
|
|
19 |
sub new ($) { |
sub new ($) { |
20 |
return bless {nav => []}, shift; |
return bless {nav => [], section_rank => 1}, shift; |
21 |
} # new |
} # new |
22 |
|
|
23 |
sub input ($;$) { |
sub input ($;$) { |
91 |
|
|
92 |
sub start_section ($%) { |
sub start_section ($%) { |
93 |
my ($self, %opt) = @_; |
my ($self, %opt) = @_; |
94 |
|
|
95 |
|
if (defined $opt{role}) { |
96 |
|
if ($opt{role} eq 'parse-errors') { |
97 |
|
$opt{id} ||= 'parse-errors'; |
98 |
|
$opt{title} ||= 'Parse Errors'; |
99 |
|
delete $opt{role}; |
100 |
|
} elsif ($opt{role} eq 'structure-errors') { |
101 |
|
$opt{id} ||= 'document-errors'; |
102 |
|
$opt{title} ||= 'Structural Errors'; |
103 |
|
$opt{short_title} ||= 'Struct. Errors'; |
104 |
|
delete $opt{role}; |
105 |
|
} elsif ($opt{role} eq 'reformatted') { |
106 |
|
$opt{id} ||= 'document-tree'; |
107 |
|
$opt{title} ||= 'Reformatted Document Source'; |
108 |
|
$opt{short_title} ||= 'Reformatted'; |
109 |
|
delete $opt{role} |
110 |
|
} elsif ($opt{role} eq 'tree') { |
111 |
|
$opt{id} ||= 'document-tree'; |
112 |
|
$opt{title} ||= 'Document Tree'; |
113 |
|
$opt{short_title} ||= 'Tree'; |
114 |
|
delete $opt{role}; |
115 |
|
} elsif ($opt{role} eq 'structure') { |
116 |
|
$opt{id} ||= 'document-structure'; |
117 |
|
$opt{title} ||= 'Document Structure'; |
118 |
|
$opt{short_title} ||= 'Structure'; |
119 |
|
delete $opt{role}; |
120 |
|
} |
121 |
|
} |
122 |
|
|
123 |
|
$self->{section_rank}++; |
124 |
$self->html ('<div class=section'); |
$self->html ('<div class=section'); |
125 |
if (defined $opt{id}) { |
if (defined $opt{id}) { |
126 |
my $id = $self->input->id_prefix . $opt{id}; |
my $id = $self->input->id_prefix . $opt{id}; |
127 |
$self->html (' id="' . $htescape->($id) . '"'); |
$self->html (' id="' . $htescape->($id) . '"'); |
128 |
push @{$self->{nav}}, [$id => $opt{short_title} || $opt{title}] |
push @{$self->{nav}}, [$id => $opt{short_title} || $opt{title}] |
129 |
unless $self->input->nested; |
if $self->{section_rank} == 2; |
130 |
} |
} |
131 |
$self->html ('><h2>' . $htescape->($opt{title}) . '</h2>'); |
my $section_rank = $self->{section_rank}; |
132 |
|
$section_rank = 6 if $section_rank > 6; |
133 |
|
$self->html ('><h' . $section_rank . '>' . |
134 |
|
$htescape->($opt{title}) . |
135 |
|
'</h' . $section_rank . '>'); |
136 |
} # start_section |
} # start_section |
137 |
|
|
138 |
sub end_section ($) { |
sub end_section ($) { |
139 |
my $self = shift; |
my $self = shift; |
140 |
$self->html ('</div>'); |
$self->html ('</div>'); |
141 |
$self->{handle}->flush; |
$self->{handle}->flush; |
142 |
|
$self->{section_rank}--; |
143 |
} # end_section |
} # end_section |
144 |
|
|
145 |
|
sub start_error_list ($%) { |
146 |
|
my ($self, %opt) = @_; |
147 |
|
|
148 |
|
if (defined $opt{role}) { |
149 |
|
if ($opt{role} eq 'parse-errors') { |
150 |
|
$opt{id} ||= 'parse-errors-list'; |
151 |
|
delete $opt{role}; |
152 |
|
} elsif ($opt{role} eq 'structure-errors') { |
153 |
|
$opt{id} ||= 'document-errors-list'; |
154 |
|
delete $opt{role}; |
155 |
|
} |
156 |
|
} |
157 |
|
|
158 |
|
$self->start_tag ('dl', %opt); |
159 |
|
} # start_error_list |
160 |
|
|
161 |
|
sub end_error_list ($%) { |
162 |
|
my ($self, %opt) = @_; |
163 |
|
|
164 |
|
if (defined $opt{role}) { |
165 |
|
if ($opt{role} eq 'parse-errors') { |
166 |
|
delete $opt{role}; |
167 |
|
$self->end_tag ('dl'); |
168 |
|
## NOTE: For parse error list, the |add_source_to_parse_error_list| |
169 |
|
## method is invoked at the end of |generate_source_string_section|, |
170 |
|
## since that generation method is invoked after the error list |
171 |
|
## is generated. |
172 |
|
} elsif ($opt{role} eq 'structure-errors') { |
173 |
|
delete $opt{role}; |
174 |
|
$self->end_tag ('dl'); |
175 |
|
$self->add_source_to_parse_error_list ('document-errors-list'); |
176 |
|
} else { |
177 |
|
$self->end_tag ('dl'); |
178 |
|
} |
179 |
|
} else { |
180 |
|
$self->end_tag ('dl'); |
181 |
|
} |
182 |
|
} # end_error_list |
183 |
|
|
184 |
|
sub add_source_to_parse_error_list ($$) { |
185 |
|
my $self = shift; |
186 |
|
|
187 |
|
$self->script (q[addSourceToParseErrorList ('] . $self->input->id_prefix . |
188 |
|
q[', '] . shift . q[')]); |
189 |
|
} # add_source_to_parse_error_list |
190 |
|
|
191 |
sub start_code_block ($) { |
sub start_code_block ($) { |
192 |
shift->html ('<pre><code>'); |
shift->html ('<pre><code>'); |
193 |
} # start_code_block |
} # start_code_block |
278 |
$self->html ('</ul>'); |
$self->html ('</ul>'); |
279 |
} # nav_list |
} # nav_list |
280 |
|
|
281 |
|
sub http_header ($) { |
282 |
|
shift->html (qq[Content-Type: text/html; charset=utf-8\n\n]); |
283 |
|
} # http_header |
284 |
|
|
285 |
|
sub http_error ($$) { |
286 |
|
my $self = shift; |
287 |
|
my $code = 0+shift; |
288 |
|
my $text = { |
289 |
|
404 => 'Not Found', |
290 |
|
}->{$code}; |
291 |
|
$self->html (qq[Status: $code $text\nContent-Type: text/html ; charset=us-ascii\n\n$code $text]); |
292 |
|
} # http_error |
293 |
|
|
294 |
|
sub html_header ($) { |
295 |
|
my $self = shift; |
296 |
|
$self->html (q[<!DOCTYPE html> |
297 |
|
<html lang="en"> |
298 |
|
<head> |
299 |
|
<title>Web Document Conformance Checker (BETA)</title> |
300 |
|
<link rel="stylesheet" href="../cc-style.css" type="text/css"> |
301 |
|
</head> |
302 |
|
<body> |
303 |
|
<h1><a href="../cc-interface">Web Document Conformance Checker</a> |
304 |
|
(<em>beta</em>)</h1> |
305 |
|
]); |
306 |
|
} # html_header |
307 |
|
|
308 |
sub encode_url_component ($$) { |
sub encode_url_component ($$) { |
309 |
shift; |
shift; |