You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

323 lines
11KB

  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 style="width: 95%; margin: auto">
  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. # Customized file ending
  167. sub ffmpeg_end_file($)
  168. {
  169. my $self = shift;
  170. my $program_string = &{$self->{'format_program_string'}}($self);
  171. my $program_text = <<EOT;
  172. <p style="font-size: small;">
  173. $program_string
  174. </p>
  175. EOT
  176. my $footer = $ENV{FFMPEG_FOOTER} || <<EOT;
  177. </div>
  178. </body>
  179. </html>
  180. EOT
  181. return $program_text . $footer;
  182. }
  183. texinfo_register_formatting_function('end_file', \&ffmpeg_end_file);
  184. # Dummy title command
  185. # Ignore title. Title is handled through ffmpeg_begin_file().
  186. set_from_init_file('USE_TITLEPAGE_FOR_TITLE', 1);
  187. sub ffmpeg_title($$$$)
  188. {
  189. return '';
  190. }
  191. texinfo_register_command_formatting('titlefont',
  192. \&ffmpeg_title);
  193. # Customized float command. Part of code borrowed from GNU Texinfo.
  194. sub ffmpeg_float($$$$$)
  195. {
  196. my $self = shift;
  197. my $cmdname = shift;
  198. my $command = shift;
  199. my $args = shift;
  200. my $content = shift;
  201. my ($caption, $prepended) = Texinfo::Common::float_name_caption($self,
  202. $command);
  203. my $caption_text = '';
  204. my $prepended_text;
  205. my $prepended_save = '';
  206. if ($self->in_string()) {
  207. if ($prepended) {
  208. $prepended_text = $self->convert_tree_new_formatting_context(
  209. $prepended, 'float prepended');
  210. } else {
  211. $prepended_text = '';
  212. }
  213. if ($caption) {
  214. $caption_text = $self->convert_tree_new_formatting_context(
  215. {'contents' => $caption->{'args'}->[0]->{'contents'}},
  216. 'float caption');
  217. }
  218. return $prepended.$content.$caption_text;
  219. }
  220. my $id = $self->command_id($command);
  221. my $label;
  222. if (defined($id) and $id ne '') {
  223. $label = "<a name=\"$id\"></a>";
  224. } else {
  225. $label = '';
  226. }
  227. if ($prepended) {
  228. if ($caption) {
  229. # prepend the prepended tree to the first paragraph
  230. my @caption_original_contents = @{$caption->{'args'}->[0]->{'contents'}};
  231. my @caption_contents;
  232. my $new_paragraph;
  233. while (@caption_original_contents) {
  234. my $content = shift @caption_original_contents;
  235. if ($content->{'type'} and $content->{'type'} eq 'paragraph') {
  236. %{$new_paragraph} = %{$content};
  237. $new_paragraph->{'contents'} = [@{$content->{'contents'}}];
  238. unshift (@{$new_paragraph->{'contents'}}, {'cmdname' => 'strong',
  239. 'args' => [{'type' => 'brace_command_arg',
  240. 'contents' => [$prepended]}]});
  241. push @caption_contents, $new_paragraph;
  242. last;
  243. } else {
  244. push @caption_contents, $content;
  245. }
  246. }
  247. push @caption_contents, @caption_original_contents;
  248. if ($new_paragraph) {
  249. $caption_text = $self->convert_tree_new_formatting_context(
  250. {'contents' => \@caption_contents}, 'float caption');
  251. $prepended_text = '';
  252. }
  253. }
  254. if ($caption_text eq '') {
  255. $prepended_text = $self->convert_tree_new_formatting_context(
  256. $prepended, 'float prepended');
  257. if ($prepended_text ne '') {
  258. $prepended_save = $prepended_text;
  259. $prepended_text = '<p><strong>'.$prepended_text.'</strong></p>';
  260. }
  261. }
  262. } else {
  263. $prepended_text = '';
  264. }
  265. if ($caption and $caption_text eq '') {
  266. $caption_text = $self->convert_tree_new_formatting_context(
  267. $caption->{'args'}->[0], 'float caption');
  268. }
  269. if ($prepended_text.$caption_text ne '') {
  270. $prepended_text = $self->_attribute_class('div','float-caption'). '>'
  271. . $prepended_text;
  272. $caption_text .= '</div>';
  273. }
  274. my $html_class = '';
  275. if ($prepended_save =~ /NOTE/) {
  276. $html_class = 'info';
  277. $prepended_text = '';
  278. $caption_text = '';
  279. } elsif ($prepended_save =~ /IMPORTANT/) {
  280. $html_class = 'warning';
  281. $prepended_text = '';
  282. $caption_text = '';
  283. }
  284. return $self->_attribute_class('div', $html_class). '>' . "\n" .
  285. $prepended_text . $caption_text . $content . '</div>';
  286. }
  287. texinfo_register_command_formatting('float',
  288. \&ffmpeg_float);
  289. 1;