blob: e83d564a65458a099f56e3dd05a7bca21551dfc1
1 | # makeinfo HTML output init file |
2 | # |
3 | # Copyright (c) 2011, 2012 Free Software Foundation, Inc. |
4 | # Copyright (c) 2014 Andreas Cadhalpun |
5 | # Copyright (c) 2014 Tiancheng "Timothy" Gu |
6 | # |
7 | # This file is part of FFmpeg. |
8 | # |
9 | # FFmpeg is free software; you can redistribute it and/or modify |
10 | # it under the terms of the GNU General Public License as published by |
11 | # the Free Software Foundation; either version 3 of the License, or |
12 | # (at your option) any later version. |
13 | # |
14 | # FFmpeg is distributed in the hope that it will be useful, |
15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
17 | # General Public License for more details. |
18 | # |
19 | # You should have received a copy of the GNU General Public |
20 | # License along with FFmpeg; if not, write to the Free Software |
21 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
22 | |
23 | # no navigation elements |
24 | set_from_init_file('HEADERS', 0); |
25 | |
26 | sub ffmpeg_heading_command($$$$$) |
27 | { |
28 | my $self = shift; |
29 | my $cmdname = shift; |
30 | my $command = shift; |
31 | my $args = shift; |
32 | my $content = shift; |
33 | |
34 | my $result = ''; |
35 | |
36 | # not clear that it may really happen |
37 | if ($self->in_string) { |
38 | $result .= $self->command_string($command) ."\n" if ($cmdname ne 'node'); |
39 | $result .= $content if (defined($content)); |
40 | return $result; |
41 | } |
42 | |
43 | my $element_id = $self->command_id($command); |
44 | $result .= "<a name=\"$element_id\"></a>\n" |
45 | if (defined($element_id) and $element_id ne ''); |
46 | |
47 | print STDERR "Process $command " |
48 | .Texinfo::Structuring::_print_root_command_texi($command)."\n" |
49 | if ($self->get_conf('DEBUG')); |
50 | my $element; |
51 | if ($Texinfo::Common::root_commands{$command->{'cmdname'}} |
52 | and $command->{'parent'} |
53 | and $command->{'parent'}->{'type'} |
54 | and $command->{'parent'}->{'type'} eq 'element') { |
55 | $element = $command->{'parent'}; |
56 | } |
57 | if ($element) { |
58 | $result .= &{$self->{'format_element_header'}}($self, $cmdname, |
59 | $command, $element); |
60 | } |
61 | |
62 | my $heading_level; |
63 | # node is used as heading if there is nothing else. |
64 | if ($cmdname eq 'node') { |
65 | if (!$element or (!$element->{'extra'}->{'section'} |
66 | and $element->{'extra'}->{'node'} |
67 | and $element->{'extra'}->{'node'} eq $command |
68 | # bogus node may not have been normalized |
69 | and defined($command->{'extra'}->{'normalized'}))) { |
70 | if ($command->{'extra'}->{'normalized'} eq 'Top') { |
71 | $heading_level = 0; |
72 | } else { |
73 | $heading_level = 3; |
74 | } |
75 | } |
76 | } else { |
77 | $heading_level = $command->{'level'}; |
78 | } |
79 | |
80 | my $heading = $self->command_text($command); |
81 | # $heading not defined may happen if the command is a @node, for example |
82 | # if there is an error in the node. |
83 | if (defined($heading) and $heading ne '' and defined($heading_level)) { |
84 | |
85 | if ($Texinfo::Common::root_commands{$cmdname} |
86 | and $Texinfo::Common::sectioning_commands{$cmdname}) { |
87 | my $content_href = $self->command_contents_href($command, 'contents', |
88 | $self->{'current_filename'}); |
89 | if ($content_href) { |
90 | my $this_href = $content_href =~ s/^\#toc-/\#/r; |
91 | $heading .= '<span class="pull-right">'. |
92 | '<a class="anchor hidden-xs" '. |
93 | "href=\"$this_href\" aria-hidden=\"true\">". |
94 | ($ENV{"FA_ICONS"} ? '<i class="fa fa-link"></i>' |
95 | : '#'). |
96 | '</a> '. |
97 | '<a class="anchor hidden-xs"'. |
98 | "href=\"$content_href\" aria-hidden=\"true\">". |
99 | ($ENV{"FA_ICONS"} ? '<i class="fa fa-navicon"></i>' |
100 | : 'TOC'). |
101 | '</a>'. |
102 | '</span>'; |
103 | } |
104 | } |
105 | |
106 | if ($self->in_preformatted()) { |
107 | $result .= $heading."\n"; |
108 | } else { |
109 | # if the level was changed, set the command name right |
110 | if ($cmdname ne 'node' |
111 | and $heading_level ne $Texinfo::Common::command_structuring_level{$cmdname}) { |
112 | $cmdname |
113 | = $Texinfo::Common::level_to_structuring_command{$cmdname}->[$heading_level]; |
114 | } |
115 | $result .= &{$self->{'format_heading_text'}}( |
116 | $self, $cmdname, $heading, |
117 | $heading_level + |
118 | $self->get_conf('CHAPTER_HEADER_LEVEL') - 1, $command); |
119 | } |
120 | } |
121 | $result .= $content if (defined($content)); |
122 | return $result; |
123 | } |
124 | |
125 | foreach my $command (keys(%Texinfo::Common::sectioning_commands), 'node') { |
126 | texinfo_register_command_formatting($command, \&ffmpeg_heading_command); |
127 | } |
128 | |
129 | # print the TOC where @contents is used |
130 | set_from_init_file('INLINE_CONTENTS', 1); |
131 | |
132 | # make chapters <h2> |
133 | set_from_init_file('CHAPTER_HEADER_LEVEL', 2); |
134 | |
135 | # Do not add <hr> |
136 | set_from_init_file('DEFAULT_RULE', ''); |
137 | set_from_init_file('BIG_RULE', ''); |
138 | |
139 | # Customized file beginning |
140 | sub ffmpeg_begin_file($$$) |
141 | { |
142 | my $self = shift; |
143 | my $filename = shift; |
144 | my $element = shift; |
145 | |
146 | my $command; |
147 | if ($element and $self->get_conf('SPLIT')) { |
148 | $command = $self->element_command($element); |
149 | } |
150 | |
151 | my ($title, $description, $encoding, $date, $css_lines, |
152 | $doctype, $bodytext, $copying_comment, $after_body_open, |
153 | $extra_head, $program_and_version, $program_homepage, |
154 | $program, $generator) = $self->_file_header_informations($command); |
155 | |
156 | my $links = $self->_get_links ($filename, $element); |
157 | |
158 | my $head1 = $ENV{"FFMPEG_HEADER1"} || <<EOT; |
159 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> |
160 | <html> |
161 | <!-- Created by $program_and_version, $program_homepage --> |
162 | <head> |
163 | <meta charset="utf-8"> |
164 | <title> |
165 | EOT |
166 | my $head_title = <<EOT; |
167 | $title |
168 | EOT |
169 | |
170 | my $head2 = $ENV{"FFMPEG_HEADER2"} || <<EOT; |
171 | </title> |
172 | <meta name="viewport" content="width=device-width,initial-scale=1.0"> |
173 | <link rel="stylesheet" type="text/css" href="bootstrap.min.css"> |
174 | <link rel="stylesheet" type="text/css" href="style.min.css"> |
175 | </head> |
176 | <body> |
177 | <div class="container"> |
178 | <h1> |
179 | EOT |
180 | |
181 | my $head3 = $ENV{"FFMPEG_HEADER3"} || <<EOT; |
182 | </h1> |
183 | EOT |
184 | |
185 | return $head1 . $head_title . $head2 . $head_title . $head3; |
186 | } |
187 | texinfo_register_formatting_function('begin_file', \&ffmpeg_begin_file); |
188 | |
189 | sub ffmpeg_program_string($) |
190 | { |
191 | my $self = shift; |
192 | if (defined($self->get_conf('PROGRAM')) |
193 | and $self->get_conf('PROGRAM') ne '' |
194 | and defined($self->get_conf('PACKAGE_URL'))) { |
195 | return $self->convert_tree( |
196 | $self->gdt('This document was generated using @uref{{program_homepage}, @emph{{program}}}.', |
197 | { 'program_homepage' => $self->get_conf('PACKAGE_URL'), |
198 | 'program' => $self->get_conf('PROGRAM') })); |
199 | } else { |
200 | return $self->convert_tree( |
201 | $self->gdt('This document was generated automatically.')); |
202 | } |
203 | } |
204 | texinfo_register_formatting_function('program_string', \&ffmpeg_program_string); |
205 | |
206 | # Customized file ending |
207 | sub ffmpeg_end_file($) |
208 | { |
209 | my $self = shift; |
210 | my $program_string = &{$self->{'format_program_string'}}($self); |
211 | my $program_text = <<EOT; |
212 | <p style="font-size: small;"> |
213 | $program_string |
214 | </p> |
215 | EOT |
216 | my $footer = $ENV{FFMPEG_FOOTER} || <<EOT; |
217 | </div> |
218 | </body> |
219 | </html> |
220 | EOT |
221 | return $program_text . $footer; |
222 | } |
223 | texinfo_register_formatting_function('end_file', \&ffmpeg_end_file); |
224 | |
225 | # Dummy title command |
226 | # Ignore title. Title is handled through ffmpeg_begin_file(). |
227 | set_from_init_file('USE_TITLEPAGE_FOR_TITLE', 1); |
228 | sub ffmpeg_title($$$$) |
229 | { |
230 | return ''; |
231 | } |
232 | |
233 | texinfo_register_command_formatting('titlefont', |
234 | \&ffmpeg_title); |
235 | |
236 | # Customized float command. Part of code borrowed from GNU Texinfo. |
237 | sub ffmpeg_float($$$$$) |
238 | { |
239 | my $self = shift; |
240 | my $cmdname = shift; |
241 | my $command = shift; |
242 | my $args = shift; |
243 | my $content = shift; |
244 | |
245 | my ($caption, $prepended) = Texinfo::Common::float_name_caption($self, |
246 | $command); |
247 | my $caption_text = ''; |
248 | my $prepended_text; |
249 | my $prepended_save = ''; |
250 | |
251 | if ($self->in_string()) { |
252 | if ($prepended) { |
253 | $prepended_text = $self->convert_tree_new_formatting_context( |
254 | $prepended, 'float prepended'); |
255 | } else { |
256 | $prepended_text = ''; |
257 | } |
258 | if ($caption) { |
259 | $caption_text = $self->convert_tree_new_formatting_context( |
260 | {'contents' => $caption->{'args'}->[0]->{'contents'}}, |
261 | 'float caption'); |
262 | } |
263 | return $prepended.$content.$caption_text; |
264 | } |
265 | |
266 | my $id = $self->command_id($command); |
267 | my $label; |
268 | if (defined($id) and $id ne '') { |
269 | $label = "<a name=\"$id\"></a>"; |
270 | } else { |
271 | $label = ''; |
272 | } |
273 | |
274 | if ($prepended) { |
275 | if ($caption) { |
276 | # prepend the prepended tree to the first paragraph |
277 | my @caption_original_contents = @{$caption->{'args'}->[0]->{'contents'}}; |
278 | my @caption_contents; |
279 | my $new_paragraph; |
280 | while (@caption_original_contents) { |
281 | my $content = shift @caption_original_contents; |
282 | if ($content->{'type'} and $content->{'type'} eq 'paragraph') { |
283 | %{$new_paragraph} = %{$content}; |
284 | $new_paragraph->{'contents'} = [@{$content->{'contents'}}]; |
285 | unshift (@{$new_paragraph->{'contents'}}, {'cmdname' => 'strong', |
286 | 'args' => [{'type' => 'brace_command_arg', |
287 | 'contents' => [$prepended]}]}); |
288 | push @caption_contents, $new_paragraph; |
289 | last; |
290 | } else { |
291 | push @caption_contents, $content; |
292 | } |
293 | } |
294 | push @caption_contents, @caption_original_contents; |
295 | if ($new_paragraph) { |
296 | $caption_text = $self->convert_tree_new_formatting_context( |
297 | {'contents' => \@caption_contents}, 'float caption'); |
298 | $prepended_text = ''; |
299 | } |
300 | } |
301 | if ($caption_text eq '') { |
302 | $prepended_text = $self->convert_tree_new_formatting_context( |
303 | $prepended, 'float prepended'); |
304 | if ($prepended_text ne '') { |
305 | $prepended_save = $prepended_text; |
306 | $prepended_text = '<p><strong>'.$prepended_text.'</strong></p>'; |
307 | } |
308 | } |
309 | } else { |
310 | $prepended_text = ''; |
311 | } |
312 | |
313 | if ($caption and $caption_text eq '') { |
314 | $caption_text = $self->convert_tree_new_formatting_context( |
315 | $caption->{'args'}->[0], 'float caption'); |
316 | } |
317 | if ($prepended_text.$caption_text ne '') { |
318 | $prepended_text = $self->_attribute_class('div','float-caption'). '>' |
319 | . $prepended_text; |
320 | $caption_text .= '</div>'; |
321 | } |
322 | my $html_class = ''; |
323 | if ($prepended_save =~ /NOTE/) { |
324 | $html_class = 'info'; |
325 | $prepended_text = ''; |
326 | $caption_text = ''; |
327 | } elsif ($prepended_save =~ /IMPORTANT/) { |
328 | $html_class = 'warning'; |
329 | $prepended_text = ''; |
330 | $caption_text = ''; |
331 | } |
332 | return $self->_attribute_class('div', $html_class). '>' . "\n" . |
333 | $prepended_text . $caption_text . $content . '</div>'; |
334 | } |
335 | |
336 | texinfo_register_command_formatting('float', |
337 | \&ffmpeg_float); |
338 | |
339 | 1; |
340 |