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
5454 }
5555
5656 # determine texinfo version
57−my $program_version_num = version->declare(ff_get_conf('PACKAGE_VERSION'))->numify;
57+my $package_version = ff_get_conf('PACKAGE_VERSION');
58+$package_version =~ s/\+dev$//;
59+my $program_version_num = version->declare($package_version)->numify;
5860 my $program_version_6_8 = $program_version_num >= 6.008000;
5961
6062 # no navigation elements
6163 ff_set_from_init_file('HEADERS', 0);
6264
65+my %sectioning_commands = %Texinfo::Common::sectioning_commands;
66+if (scalar(keys(%sectioning_commands)) == 0) {
67+ %sectioning_commands = %Texinfo::Commands::sectioning_heading_commands;
68+}
69+
70+my %root_commands = %Texinfo::Common::root_commands;
71+if (scalar(keys(%root_commands)) == 0) {
72+ %root_commands = %Texinfo::Commands::root_commands;
73+}
74+
6375 sub ffmpeg_heading_command($$$$$)
6476 {
6577 my $self = shift;
@@ -77,6 +89,9 @@ sub ffmpeg_heading_command($$$$$) · 11 unmodified lines
7789 return $result;
7890 }
7991
92+ # no need to set it as the $element_id is output unconditionally
93+ my $heading_id;
94+
8095 my $element_id = $self->command_id($command);
8196 $result .= "<a name=\"$element_id\"></a>\n"
8297 if (defined($element_id) and $element_id ne '');
@@ -84,24 +99,40 @@ sub ffmpeg_heading_command($$$$$) · 1 unmodified line
8499 print STDERR "Process $command "
85100 .Texinfo::Structuring::_print_root_command_texi($command)."\n"
86101 if ($self->get_conf('DEBUG'));
87− my $element;
88− if ($Texinfo::Common::root_commands{$command->{'cmdname'}}
89− and $command->{'parent'}
90− and $command->{'parent'}->{'type'}
91− and $command->{'parent'}->{'type'} eq 'element') {
92− $element = $command->{'parent'};
102+ my $output_unit;
103+ if ($root_commands{$command->{'cmdname'}}) {
104+ if ($command->{'associated_unit'}) {
105+ $output_unit = $command->{'associated_unit'};
106+ } elsif ($command->{'structure'}
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+ }
93114 }
94− if ($element) {
115+
116+ if ($output_unit) {
95117 $result .= &{get_formatting_function($self, 'format_element_header')}($self, $cmdname,
96− $command, $element);
118+ $command, $output_unit);
97119 }
98120
99121 my $heading_level;
100122 # node is used as heading if there is nothing else.
101123 if ($cmdname eq 'node') {
102− if (!$element or (!$element->{'extra'}->{'section'}
103− and $element->{'extra'}->{'node'}
104− and $element->{'extra'}->{'node'} eq $command
124+ if (!$output_unit or
125+ (((!$output_unit->{'extra'}->{'section'}
126+ 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'}))
105136 # bogus node may not have been normalized
106137 and defined($command->{'extra'}->{'normalized'}))) {
107138 if ($command->{'extra'}->{'normalized'} eq 'Top') {
@@ -111,7 +142,15 @@ sub ffmpeg_heading_command($$$$$) · 3 unmodified lines
111142 }
112143 }
113144 } 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+ }
115154 }
116155
117156 my $heading = $self->command_text($command);
@@ -119,8 +158,8 @@ sub ffmpeg_heading_command($$$$$) · 1 unmodified line
119158 # if there is an error in the node.
120159 if (defined($heading) and $heading ne '' and defined($heading_level)) {
121160
122− if ($Texinfo::Common::root_commands{$cmdname}
123− and $Texinfo::Common::sectioning_commands{$cmdname}) {
161+ if ($root_commands{$cmdname}
162+ and $sectioning_commands{$cmdname}) {
124163 my $content_href = $self->command_contents_href($command, 'contents',
125164 $self->{'current_filename'});
126165 if ($content_href) {
@@ -140,7 +179,13 @@ sub ffmpeg_heading_command($$$$$) · 13 unmodified lines
140179 }
141180 }
142181
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) {
144189 $result .= $heading."\n";
145190 } else {
146191 # if the level was changed, set the command name right
@@ -149,21 +194,25 @@ sub ffmpeg_heading_command($$$$$) · 2 unmodified lines
149194 $cmdname
150195 = $Texinfo::Common::level_to_structuring_command{$cmdname}->[$heading_level];
151196 }
152− # format_heading_text expects an array of headings for texinfo >= 7.0
153197 if ($program_version_num >= 7.000000) {
154− $heading = [$heading];
155− }
156− $result .= &{get_formatting_function($self,'format_heading_text')}(
198+ $result .= &{get_formatting_function($self,'format_heading_text')}($self,
199+ $cmdname, [$cmdname], $heading,
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')}(
157205 $self, $cmdname, $heading,
158206 $heading_level +
159207 $self->get_conf('CHAPTER_HEADER_LEVEL') - 1, $command);
208+ }
160209 }
161210 }
162211 $result .= $content if (defined($content));
163212 return $result;
164213 }
165214
166−foreach my $command (keys(%Texinfo::Common::sectioning_commands), 'node') {
215+foreach my $command (keys(%sectioning_commands), 'node') {
167216 texinfo_register_command_formatting($command, \&ffmpeg_heading_command);
168217 }
169218
@@ -188,28 +237,56 @@ sub ffmpeg_begin_file($$$) · 18 unmodified lines
188237 my $filename = shift;
189238 my $element = shift;
190239
191− my $command;
192− if ($element and $self->get_conf('SPLIT')) {
193− $command = $self->element_command($element);
240+ my ($element_command, $node_command, $command_for_title);
241+ if ($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'));
194259 }
195260
196− my ($title, $description, $encoding, $date, $css_lines,
197− $doctype, $bodytext, $copying_comment, $after_body_open,
198− $extra_head, $program_and_version, $program_homepage,
261+ my ($title, $description, $keywords, $encoding, $date, $css_lines, $doctype,
262+ $root_html_element_attributes, $body_attributes, $copying_comment,
263+ $after_body_open, $extra_head, $program_and_version, $program_homepage,
199264 $program, $generator);
200− if ($program_version_num >= 7.000000) {
201− ($title, $description, $encoding, $date, $css_lines,
202− $doctype, $bodytext, $copying_comment, $after_body_open,
265+ if ($program_version_num >= 7.001090) {
266+ ($title, $description, $keywords, $encoding, $date, $css_lines, $doctype,
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,
203274 $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);
205277 } else {
206278 ($title, $description, $encoding, $date, $css_lines,
207− $doctype, $bodytext, $copying_comment, $after_body_open,
208− $extra_head, $program_and_version, $program_homepage,
209− $program, $generator) = $self->_file_header_informations($command);
279+ $doctype, $root_html_element_attributes, $copying_comment,
280+ $after_body_open, $extra_head, $program_and_version, $program_homepage,
281+ $program, $generator) = $self->_file_header_informations($command_for_title);
210282 }
211283
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+ }
213290
214291 my $head1 = $ENV{"FFMPEG_HEADER1"} || <<EOT;
215292 <!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
252329 if (defined($self->get_conf('PROGRAM'))
253330 and $self->get_conf('PROGRAM') ne ''
254331 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(
256339 $self->gdt('This document was generated using @uref{{program_homepage}, @emph{{program}}}.',
257− { 'program_homepage' => $self->get_conf('PACKAGE_URL'),
258− 'program' => $self->get_conf('PROGRAM') }));
340+ { 'program_homepage' => {'text' => $self->get_conf('PACKAGE_URL')},
341+ 'program' => {'text' => $self->get_conf('PROGRAM') }}));
342+ }
259343 } else {
260− return $self->convert_tree(
261− $self->gdt('This document was generated automatically.'));
344+ if ($program_version_num >= 7.001090) {
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+ }
262351 }
263352 }
264353 if ($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