t2h.pm 12 KB

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