t2h.pm 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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. # TOC and Chapter headings link
  25. set_from_init_file('TOC_LINKS', 1);
  26. # print the TOC where @contents is used
  27. set_from_init_file('INLINE_CONTENTS', 1);
  28. # make chapters <h2>
  29. set_from_init_file('CHAPTER_HEADER_LEVEL', 2);
  30. # Do not add <hr>
  31. set_from_init_file('DEFAULT_RULE', '');
  32. set_from_init_file('BIG_RULE', '');
  33. # Customized file beginning
  34. sub ffmpeg_begin_file($$$)
  35. {
  36. my $self = shift;
  37. my $filename = shift;
  38. my $element = shift;
  39. my $command;
  40. if ($element and $self->get_conf('SPLIT')) {
  41. $command = $self->element_command($element);
  42. }
  43. my ($title, $description, $encoding, $date, $css_lines,
  44. $doctype, $bodytext, $copying_comment, $after_body_open,
  45. $extra_head, $program_and_version, $program_homepage,
  46. $program, $generator) = $self->_file_header_informations($command);
  47. my $links = $self->_get_links ($filename, $element);
  48. my $head1 = $ENV{"FFMPEG_HEADER1"} || <<EOT;
  49. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  50. <html>
  51. <!-- Created by $program_and_version, $program_homepage -->
  52. <head>
  53. <meta charset="utf-8">
  54. <title>
  55. EOT
  56. my $head_title = <<EOT;
  57. $title
  58. EOT
  59. my $head2 = $ENV{"FFMPEG_HEADER2"} || <<EOT;
  60. </title>
  61. <link rel="stylesheet" type="text/css" href="bootstrap.min.css">
  62. <link rel="stylesheet" type="text/css" href="style.min.css">
  63. </head>
  64. <body>
  65. <div style="width: 95%; margin: auto">
  66. <h1>
  67. EOT
  68. my $head3 = $ENV{"FFMPEG_HEADER3"} || <<EOT;
  69. </h1>
  70. EOT
  71. return $head1 . $head_title . $head2 . $head_title . $head3;
  72. }
  73. texinfo_register_formatting_function('begin_file', \&ffmpeg_begin_file);
  74. # Customized file ending
  75. sub ffmpeg_end_file($)
  76. {
  77. my $self = shift;
  78. my $program_string = &{$self->{'format_program_string'}}($self);
  79. my $program_text = <<EOT;
  80. <p style="font-size: small;">
  81. $program_string
  82. </p>
  83. EOT
  84. my $footer = $ENV{FFMPEG_FOOTER} || <<EOT;
  85. </div>
  86. </body>
  87. </html>
  88. EOT
  89. return $program_text . $footer;
  90. }
  91. texinfo_register_formatting_function('end_file', \&ffmpeg_end_file);
  92. # Dummy title command
  93. # Ignore title. Title is handled through ffmpeg_begin_file().
  94. set_from_init_file('USE_TITLEPAGE_FOR_TITLE', 1);
  95. sub ffmpeg_title($$$$)
  96. {
  97. return '';
  98. }
  99. texinfo_register_command_formatting('titlefont',
  100. \&ffmpeg_title);
  101. # Customized float command. Part of code borrowed from GNU Texinfo.
  102. sub ffmpeg_float($$$$$)
  103. {
  104. my $self = shift;
  105. my $cmdname = shift;
  106. my $command = shift;
  107. my $args = shift;
  108. my $content = shift;
  109. my ($caption, $prepended) = Texinfo::Common::float_name_caption($self,
  110. $command);
  111. my $caption_text = '';
  112. my $prepended_text;
  113. my $prepended_save = '';
  114. if ($self->in_string()) {
  115. if ($prepended) {
  116. $prepended_text = $self->convert_tree_new_formatting_context(
  117. $prepended, 'float prepended');
  118. } else {
  119. $prepended_text = '';
  120. }
  121. if ($caption) {
  122. $caption_text = $self->convert_tree_new_formatting_context(
  123. {'contents' => $caption->{'args'}->[0]->{'contents'}},
  124. 'float caption');
  125. }
  126. return $prepended.$content.$caption_text;
  127. }
  128. my $id = $self->command_id($command);
  129. my $label;
  130. if (defined($id) and $id ne '') {
  131. $label = "<a name=\"$id\"></a>";
  132. } else {
  133. $label = '';
  134. }
  135. if ($prepended) {
  136. if ($caption) {
  137. # prepend the prepended tree to the first paragraph
  138. my @caption_original_contents = @{$caption->{'args'}->[0]->{'contents'}};
  139. my @caption_contents;
  140. my $new_paragraph;
  141. while (@caption_original_contents) {
  142. my $content = shift @caption_original_contents;
  143. if ($content->{'type'} and $content->{'type'} eq 'paragraph') {
  144. %{$new_paragraph} = %{$content};
  145. $new_paragraph->{'contents'} = [@{$content->{'contents'}}];
  146. unshift (@{$new_paragraph->{'contents'}}, {'cmdname' => 'strong',
  147. 'args' => [{'type' => 'brace_command_arg',
  148. 'contents' => [$prepended]}]});
  149. push @caption_contents, $new_paragraph;
  150. last;
  151. } else {
  152. push @caption_contents, $content;
  153. }
  154. }
  155. push @caption_contents, @caption_original_contents;
  156. if ($new_paragraph) {
  157. $caption_text = $self->convert_tree_new_formatting_context(
  158. {'contents' => \@caption_contents}, 'float caption');
  159. $prepended_text = '';
  160. }
  161. }
  162. if ($caption_text eq '') {
  163. $prepended_text = $self->convert_tree_new_formatting_context(
  164. $prepended, 'float prepended');
  165. if ($prepended_text ne '') {
  166. $prepended_save = $prepended_text;
  167. $prepended_text = '<p><strong>'.$prepended_text.'</strong></p>';
  168. }
  169. }
  170. } else {
  171. $prepended_text = '';
  172. }
  173. if ($caption and $caption_text eq '') {
  174. $caption_text = $self->convert_tree_new_formatting_context(
  175. $caption->{'args'}->[0], 'float caption');
  176. }
  177. if ($prepended_text.$caption_text ne '') {
  178. $prepended_text = $self->_attribute_class('div','float-caption'). '>'
  179. . $prepended_text;
  180. $caption_text .= '</div>';
  181. }
  182. my $html_class = '';
  183. if ($prepended_save =~ /NOTE/) {
  184. $html_class = 'info';
  185. $prepended_text = '';
  186. $caption_text = '';
  187. } elsif ($prepended_save =~ /IMPORTANT/) {
  188. $html_class = 'warning';
  189. $prepended_text = '';
  190. $caption_text = '';
  191. }
  192. return $self->_attribute_class('div', $html_class). '>' . "\n" .
  193. $prepended_text . $caption_text . $content . '</div>';
  194. }
  195. texinfo_register_command_formatting('float',
  196. \&ffmpeg_float);
  197. 1;