History

doc/t2h: Support texinfo 7.1 and 7.2 pretest

Here is a proposed patch for portability of doc/t2h.pm for GNU Texinfo 7.1 and 7.1.90 (7.2 pretest). I tested against 7.1 and 7.1.90 (7.2 pretest). There is a difference in the headings compared to the website version, maybe related to FA_ICONS not being set the same, but the result seems correct. I also renamed $element to $output_unit in ffmpeg_heading_command as in new equivalent makeinfo/texi2any code the $element variable is the $command variable in ffmpeg_heading_command, which is very confusing. I left as is the $command variable to have a patch easier to read, but it could make sense to rename $command as $element later on. The patch could also have effects with Texinfo 7.0, since some of the changes are for that version, but that probably never show up because it is for situations that may not exist in ffmpeg manuals (for example @node without sectioning command), or because the code is robust to some missing information (case of $heading_level in ffmpeg_heading_command that was not set, as far as I can tell).

Patrice Dumas committed 2 years ago

Commit 4d9cdf81 parent d1fa9cf1 file · +129 −40Browse files

Unified · Split

doc/t2h.pm+129−40
@@ -54,12 +54,24 @@ sub get_formatting_function($$) { · 53 unmodified lines
54}54}
55 55
56# determine texinfo version56# determine texinfo version
57my $program_version_num = version->declare(ff_get_conf('PACKAGE_VERSION'))->numify;57my $package_version = ff_get_conf('PACKAGE_VERSION');
58$package_version =~ s/\+dev$//;
59my $program_version_num = version->declare($package_version)->numify;
58my $program_version_6_8 = $program_version_num >= 6.008000;60my $program_version_6_8 = $program_version_num >= 6.008000;
59 61
60# no navigation elements62# no navigation elements
61ff_set_from_init_file('HEADERS', 0);63ff_set_from_init_file('HEADERS', 0);
62 64
65my %sectioning_commands = %Texinfo::Common::sectioning_commands;
66if (scalar(keys(%sectioning_commands)) == 0) {
67 %sectioning_commands = %Texinfo::Commands::sectioning_heading_commands;
68}
69
70my %root_commands = %Texinfo::Common::root_commands;
71if (scalar(keys(%root_commands)) == 0) {
72 %root_commands = %Texinfo::Commands::root_commands;
73}
74
63sub ffmpeg_heading_command($$$$$)75sub ffmpeg_heading_command($$$$$)
64{76{
65 my $self = shift;77 my $self = shift;
@@ -77,6 +89,9 @@ sub ffmpeg_heading_command($$$$$) · 11 unmodified lines
77 return $result;89 return $result;
78 }90 }
79 91
92 # no need to set it as the $element_id is output unconditionally
93 my $heading_id;
94
80 my $element_id = $self->command_id($command);95 my $element_id = $self->command_id($command);
81 $result .= "<a name=\"$element_id\"></a>\n"96 $result .= "<a name=\"$element_id\"></a>\n"
82 if (defined($element_id) and $element_id ne '');97 if (defined($element_id) and $element_id ne '');
@@ -84,24 +99,40 @@ sub ffmpeg_heading_command($$$$$) · 1 unmodified line
84 print STDERR "Process $command "99 print STDERR "Process $command "
85 .Texinfo::Structuring::_print_root_command_texi($command)."\n"100 .Texinfo::Structuring::_print_root_command_texi($command)."\n"
86 if ($self->get_conf('DEBUG'));101 if ($self->get_conf('DEBUG'));
87 my $element;102 my $output_unit;
88 if ($Texinfo::Common::root_commands{$command->{'cmdname'}}103 if ($root_commands{$command->{'cmdname'}}) {
89 and $command->{'parent'}104 if ($command->{'associated_unit'}) {
90 and $command->{'parent'}->{'type'}105 $output_unit = $command->{'associated_unit'};
91 and $command->{'parent'}->{'type'} eq 'element') {106 } elsif ($command->{'structure'}
92 $element = $command->{'parent'};107 and $command->{'structure'}->{'associated_unit'}) {
108 $output_unit = $command->{'structure'}->{'associated_unit'};
109 } elsif ($command->{'parent'}
110 and $command->{'parent'}->{'type'}
111 and $command->{'parent'}->{'type'} eq 'element') {
112 $output_unit = $command->{'parent'};
113 }
93 }114 }
94 if ($element) {115
116 if ($output_unit) {
95 $result .= &{get_formatting_function($self, 'format_element_header')}($self, $cmdname,117 $result .= &{get_formatting_function($self, 'format_element_header')}($self, $cmdname,
96 $command, $element);118 $command, $output_unit);
97 }119 }
98 120
99 my $heading_level;121 my $heading_level;
100 # node is used as heading if there is nothing else.122 # node is used as heading if there is nothing else.
101 if ($cmdname eq 'node') {123 if ($cmdname eq 'node') {
102 if (!$element or (!$element->{'extra'}->{'section'}124 if (!$output_unit or
103 and $element->{'extra'}->{'node'}125 (((!$output_unit->{'extra'}->{'section'}
104 and $element->{'extra'}->{'node'} eq $command126 and $output_unit->{'extra'}->{'node'}
127 and $output_unit->{'extra'}->{'node'} eq $command)
128 or
129 ((($output_unit->{'extra'}->{'unit_command'}
130 and $output_unit->{'extra'}->{'unit_command'} eq $command)
131 or
132 ($output_unit->{'unit_command'}
133 and $output_unit->{'unit_command'} eq $command))
134 and $command->{'extra'}
135 and not $command->{'extra'}->{'associated_section'}))
105 # bogus node may not have been normalized136 # bogus node may not have been normalized
106 and defined($command->{'extra'}->{'normalized'}))) {137 and defined($command->{'extra'}->{'normalized'}))) {
107 if ($command->{'extra'}->{'normalized'} eq 'Top') {138 if ($command->{'extra'}->{'normalized'} eq 'Top') {
@@ -111,7 +142,15 @@ sub ffmpeg_heading_command($$$$$) · 3 unmodified lines
111 }142 }
112 }143 }
113 } else {144 } else {
114 $heading_level = $command->{'level'};145 if (defined($command->{'extra'})
146 and defined($command->{'extra'}->{'section_level'})) {
147 $heading_level = $command->{'extra'}->{'section_level'};
148 } elsif ($command->{'structure'}
149 and defined($command->{'structure'}->{'section_level'})) {
150 $heading_level = $command->{'structure'}->{'section_level'};
151 } else {
152 $heading_level = $command->{'level'};
153 }
115 }154 }
116 155
117 my $heading = $self->command_text($command);156 my $heading = $self->command_text($command);
@@ -119,8 +158,8 @@ sub ffmpeg_heading_command($$$$$) · 1 unmodified line
119 # if there is an error in the node.158 # if there is an error in the node.
120 if (defined($heading) and $heading ne '' and defined($heading_level)) {159 if (defined($heading) and $heading ne '' and defined($heading_level)) {
121 160
122 if ($Texinfo::Common::root_commands{$cmdname}161 if ($root_commands{$cmdname}
123 and $Texinfo::Common::sectioning_commands{$cmdname}) {162 and $sectioning_commands{$cmdname}) {
124 my $content_href = $self->command_contents_href($command, 'contents',163 my $content_href = $self->command_contents_href($command, 'contents',
125 $self->{'current_filename'});164 $self->{'current_filename'});
126 if ($content_href) {165 if ($content_href) {
@@ -140,7 +179,13 @@ sub ffmpeg_heading_command($$$$$) · 13 unmodified lines
140 }179 }
141 }180 }
142 181
143 if ($self->in_preformatted()) {182 my $in_preformatted;
183 if ($program_version_num >= 7.001090) {
184 $in_preformatted = $self->in_preformatted_context();
185 } else {
186 $in_preformatted = $self->in_preformatted();
187 }
188 if ($in_preformatted) {
144 $result .= $heading."\n";189 $result .= $heading."\n";
145 } else {190 } else {
146 # if the level was changed, set the command name right191 # if the level was changed, set the command name right
@@ -149,21 +194,25 @@ sub ffmpeg_heading_command($$$$$) · 2 unmodified lines
149 $cmdname194 $cmdname
150 = $Texinfo::Common::level_to_structuring_command{$cmdname}->[$heading_level];195 = $Texinfo::Common::level_to_structuring_command{$cmdname}->[$heading_level];
151 }196 }
152 # format_heading_text expects an array of headings for texinfo >= 7.0
153 if ($program_version_num >= 7.000000) {197 if ($program_version_num >= 7.000000) {
154 $heading = [$heading];198 $result .= &{get_formatting_function($self,'format_heading_text')}($self,
155 }199 $cmdname, [$cmdname], $heading,
156 $result .= &{get_formatting_function($self,'format_heading_text')}(200 $heading_level +$self->get_conf('CHAPTER_HEADER_LEVEL') -1,
201 $heading_id, $command);
202
203 } else {
204 $result .= &{get_formatting_function($self,'format_heading_text')}(
157 $self, $cmdname, $heading,205 $self, $cmdname, $heading,
158 $heading_level +206 $heading_level +
159 $self->get_conf('CHAPTER_HEADER_LEVEL') - 1, $command);207 $self->get_conf('CHAPTER_HEADER_LEVEL') - 1, $command);
208 }
160 }209 }
161 }210 }
162 $result .= $content if (defined($content));211 $result .= $content if (defined($content));
163 return $result;212 return $result;
164}213}
165 214
166foreach my $command (keys(%Texinfo::Common::sectioning_commands), 'node') {215foreach my $command (keys(%sectioning_commands), 'node') {
167 texinfo_register_command_formatting($command, \&ffmpeg_heading_command);216 texinfo_register_command_formatting($command, \&ffmpeg_heading_command);
168}217}
169 218
@@ -188,28 +237,56 @@ sub ffmpeg_begin_file($$$) · 18 unmodified lines
188 my $filename = shift;237 my $filename = shift;
189 my $element = shift;238 my $element = shift;
190 239
191 my $command;240 my ($element_command, $node_command, $command_for_title);
192 if ($element and $self->get_conf('SPLIT')) {241 if ($element) {
193 $command = $self->element_command($element);242 if ($element->{'unit_command'}) {
243 $element_command = $element->{'unit_command'};
244 } elsif ($self->can('tree_unit_element_command')) {
245 $element_command = $self->tree_unit_element_command($element);
246 } elsif ($self->can('tree_unit_element_command')) {
247 $element_command = $self->element_command($element);
248 }
249
250 $node_command = $element_command;
251 if ($element_command and $element_command->{'cmdname'}
252 and $element_command->{'cmdname'} ne 'node'
253 and $element_command->{'extra'}
254 and $element_command->{'extra'}->{'associated_node'}) {
255 $node_command = $element_command->{'extra'}->{'associated_node'};
256 }
257
258 $command_for_title = $element_command if ($self->get_conf('SPLIT'));
194 }259 }
195 260
196 my ($title, $description, $encoding, $date, $css_lines,261 my ($title, $description, $keywords, $encoding, $date, $css_lines, $doctype,
197 $doctype, $bodytext, $copying_comment, $after_body_open,262 $root_html_element_attributes, $body_attributes, $copying_comment,
198 $extra_head, $program_and_version, $program_homepage,263 $after_body_open, $extra_head, $program_and_version, $program_homepage,
199 $program, $generator);264 $program, $generator);
200 if ($program_version_num >= 7.000000) {265 if ($program_version_num >= 7.001090) {
201 ($title, $description, $encoding, $date, $css_lines,266 ($title, $description, $keywords, $encoding, $date, $css_lines, $doctype,
202 $doctype, $bodytext, $copying_comment, $after_body_open,267 $root_html_element_attributes, $body_attributes, $copying_comment,
268 $after_body_open, $extra_head, $program_and_version, $program_homepage,
269 $program, $generator) = $self->_file_header_information($command_for_title,
270 $filename);
271 } elsif ($program_version_num >= 7.000000) {
272 ($title, $description, $encoding, $date, $css_lines, $doctype,
273 $root_html_element_attributes, $copying_comment, $after_body_open,
203 $extra_head, $program_and_version, $program_homepage,274 $extra_head, $program_and_version, $program_homepage,
204 $program, $generator) = $self->_file_header_information($command);275 $program, $generator) = $self->_file_header_information($command_for_title,
276 $filename);
205 } else {277 } else {
206 ($title, $description, $encoding, $date, $css_lines,278 ($title, $description, $encoding, $date, $css_lines,
207 $doctype, $bodytext, $copying_comment, $after_body_open,279 $doctype, $root_html_element_attributes, $copying_comment,
208 $extra_head, $program_and_version, $program_homepage,280 $after_body_open, $extra_head, $program_and_version, $program_homepage,
209 $program, $generator) = $self->_file_header_informations($command);281 $program, $generator) = $self->_file_header_informations($command_for_title);
210 }282 }
211 283
212 my $links = $self->_get_links ($filename, $element);284 my $links;
285 if ($program_version_num >= 7.000000) {
286 $links = $self->_get_links($filename, $element, $node_command);
287 } else {
288 $links = $self->_get_links ($filename, $element);
289 }
213 290
214 my $head1 = $ENV{"FFMPEG_HEADER1"} || <<EOT;291 my $head1 = $ENV{"FFMPEG_HEADER1"} || <<EOT;
215<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">292<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
@@ -252,13 +329,25 @@ sub ffmpeg_program_string($) · 36 unmodified lines
252 if (defined($self->get_conf('PROGRAM'))329 if (defined($self->get_conf('PROGRAM'))
253 and $self->get_conf('PROGRAM') ne ''330 and $self->get_conf('PROGRAM') ne ''
254 and defined($self->get_conf('PACKAGE_URL'))) {331 and defined($self->get_conf('PACKAGE_URL'))) {
255 return $self->convert_tree(332 if ($program_version_num >= 7.001090) {
333 return $self->convert_tree(
334 $self->cdt('This document was generated using @uref{{program_homepage}, @emph{{program}}}.',
335 { 'program_homepage' => {'text' => $self->get_conf('PACKAGE_URL')},
336 'program' => {'text' => $self->get_conf('PROGRAM') }}));
337 } else {
338 return $self->convert_tree(
256 $self->gdt('This document was generated using @uref{{program_homepage}, @emph{{program}}}.',339 $self->gdt('This document was generated using @uref{{program_homepage}, @emph{{program}}}.',
257 { 'program_homepage' => $self->get_conf('PACKAGE_URL'),340 { 'program_homepage' => {'text' => $self->get_conf('PACKAGE_URL')},
258 'program' => $self->get_conf('PROGRAM') }));341 'program' => {'text' => $self->get_conf('PROGRAM') }}));
342 }
259 } else {343 } else {
260 return $self->convert_tree(344 if ($program_version_num >= 7.001090) {
261 $self->gdt('This document was generated automatically.'));345 return $self->convert_tree(
346 $self->cdt('This document was generated automatically.'));
347 } else {
348 return $self->convert_tree(
349 $self->gdt('This document was generated automatically.'));
350 }
262 }351 }
263}352}
264if ($program_version_6_8) {353if ($program_version_6_8) {

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t