[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[no subject]
From: |
Patrice Dumas |
Date: |
Tue, 24 Dec 2024 11:25:09 -0500 (EST) |
branch: master
commit 3c9b1017a02d454f41ed66243479f99da0426ec9
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Sun Nov 24 21:01:58 2024 +0100
* tp/Texinfo/Convert/HTML.pm (_convert),
tp/Texinfo/XS/convert/convert_html.c (html_convert_tree_append):
remove the condition on arguments_list being set, it is always the
case.
---
ChangeLog | 7 +
tp/Texinfo/Convert/HTML.pm | 185 ++++++++++----------
tp/Texinfo/XS/convert/convert_html.c | 327 +++++++++++++++++------------------
3 files changed, 261 insertions(+), 258 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index a8a6614e91..0d15c03353 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2024-11-24 Patrice Dumas <pertusus@free.fr>
+
+ * tp/Texinfo/Convert/HTML.pm (_convert),
+ tp/Texinfo/XS/convert/convert_html.c (html_convert_tree_append):
+ remove the condition on arguments_list being set, it is always the
+ case.
+
2024-11-24 Patrice Dumas <pertusus@free.fr>
* tp/Texinfo/Convert/HTML.pm (_convert),
diff --git a/tp/Texinfo/Convert/HTML.pm b/tp/Texinfo/Convert/HTML.pm
index 6c0fe97f44..3ca4ef9ee6 100644
--- a/tp/Texinfo/Convert/HTML.pm
+++ b/tp/Texinfo/Convert/HTML.pm
@@ -13613,102 +13613,101 @@ sub _convert($$;$)
} else {
$arguments_list = $element->{'contents'};
}
- if ($arguments_list) {
- $args_formatted = [];
- my @args_specification;
- @args_specification = @{$html_default_commands_args{$command_name}}
- if (defined($html_default_commands_args{$command_name}));
- my $spec_nr = scalar(@args_specification);
- my $arg_idx = -1;
- foreach my $arg (@{$arguments_list}) {
- $arg_idx++;
- my $arg_spec;
- if ($arg_idx < $spec_nr) {
- $arg_spec = $args_specification[$arg_idx];
- }
- if (!$arg->{'contents'} or !scalar(@{$arg->{'contents'}})) {
- push @$args_formatted, undef;
- next;
- }
- # NOTE here commands with empty array reference in array
- # reference associated to command in html_default_commands_args
- # do not have $arg_spec reset to normal, such that their argument
- # is not converted here
- $arg_spec = ['normal'] if (!defined($arg_spec));
- my $arg_formatted = {'arg_tree' => $arg};
- foreach my $arg_type (@$arg_spec) {
- my $explanation = "$command_type A[$arg_idx]$arg_type";
- if ($arg_type eq 'normal') {
- if ($convert_to_latex) {
- $arg_formatted->{'normal'}
- = Texinfo::Convert::LaTeX::convert_to_latex_math(undef,
$arg,
-
$self->{'options_latex_math'});
- } else {
- $arg_formatted->{'normal'}
- = $self->_convert($arg, $explanation);
- }
- } elsif ($arg_type eq 'monospace') {
- _set_code_context($self, 1);
- $arg_formatted->{$arg_type} = $self->_convert($arg,
$explanation);
- _pop_code_context($self);
- } elsif ($arg_type eq 'string') {
- $self->_new_document_context($command_type);
- _set_string_context($self);
- $arg_formatted->{$arg_type} = $self->_convert($arg,
$explanation);
- #_unset_string_context($self);
- $self->_pop_document_context();
- } elsif ($arg_type eq 'monospacestring') {
- $self->_new_document_context($command_type);
- _set_code_context($self, 1);
- _set_string_context($self);
- $arg_formatted->{$arg_type} = $self->_convert($arg,
$explanation);
- #_unset_string_context($self);
- _pop_code_context($self);
- $self->_pop_document_context();
- } elsif ($arg_type eq 'monospacetext') {
- Texinfo::Convert::Text::set_options_code(
- $self->{'convert_text_options'});
- $arg_formatted->{$arg_type}
- = Texinfo::Convert::Text::convert_to_text($arg,
- $self->{'convert_text_options'});
- Texinfo::Convert::Text::reset_options_code(
- $self->{'convert_text_options'});
- } elsif ($arg_type eq 'filenametext') {
-
- Texinfo::Convert::Text::set_options_code(
- $self->{'convert_text_options'});
- # Always use encoded characters for file names
-
Texinfo::Convert::Text::set_options_encoding_if_not_ascii($self,
- $self->{'convert_text_options'});
- $arg_formatted->{$arg_type}
- = Texinfo::Convert::Text::convert_to_text($arg,
- $self->{'convert_text_options'});
- Texinfo::Convert::Text::reset_options_code(
- $self->{'convert_text_options'});
- Texinfo::Convert::Text::reset_options_encoding(
- $self->{'convert_text_options'});
- } elsif ($arg_type eq 'url') {
- Texinfo::Convert::Text::set_options_code(
- $self->{'convert_text_options'});
- # set the encoding to UTF-8 to always have a string that
- # is suitable for percent encoding.
- Texinfo::Convert::Text::set_options_encoding(
- $self->{'convert_text_options'}, 'utf-8');
- $arg_formatted->{$arg_type}
- = Texinfo::Convert::Text::convert_to_text($arg,
- $self->{'convert_text_options'});
- Texinfo::Convert::Text::reset_options_code(
- $self->{'convert_text_options'});
- Texinfo::Convert::Text::reset_options_encoding(
- $self->{'convert_text_options'});
- } elsif ($arg_type eq 'raw') {
- _set_raw_context($self);
- $arg_formatted->{$arg_type} = $self->_convert($arg,
$explanation);
- _unset_raw_context($self);
+
+ $args_formatted = [];
+ my @args_specification;
+ @args_specification = @{$html_default_commands_args{$command_name}}
+ if (defined($html_default_commands_args{$command_name}));
+ my $spec_nr = scalar(@args_specification);
+ my $arg_idx = -1;
+ foreach my $arg (@{$arguments_list}) {
+ $arg_idx++;
+ my $arg_spec;
+ if ($arg_idx < $spec_nr) {
+ $arg_spec = $args_specification[$arg_idx];
+ }
+ if (!$arg->{'contents'} or !scalar(@{$arg->{'contents'}})) {
+ push @$args_formatted, undef;
+ next;
+ }
+ # NOTE here commands with empty array reference in array
+ # reference associated to command in html_default_commands_args
+ # do not have $arg_spec reset to normal, such that their argument
+ # is not converted here
+ $arg_spec = ['normal'] if (!defined($arg_spec));
+ my $arg_formatted = {'arg_tree' => $arg};
+ foreach my $arg_type (@$arg_spec) {
+ my $explanation = "$command_type A[$arg_idx]$arg_type";
+ if ($arg_type eq 'normal') {
+ if ($convert_to_latex) {
+ $arg_formatted->{'normal'}
+ = Texinfo::Convert::LaTeX::convert_to_latex_math(undef, $arg,
+ $self->{'options_latex_math'});
+ } else {
+ $arg_formatted->{'normal'}
+ = $self->_convert($arg, $explanation);
}
+ } elsif ($arg_type eq 'monospace') {
+ _set_code_context($self, 1);
+ $arg_formatted->{$arg_type} = $self->_convert($arg,
$explanation);
+ _pop_code_context($self);
+ } elsif ($arg_type eq 'string') {
+ $self->_new_document_context($command_type);
+ _set_string_context($self);
+ $arg_formatted->{$arg_type} = $self->_convert($arg,
$explanation);
+ #_unset_string_context($self);
+ $self->_pop_document_context();
+ } elsif ($arg_type eq 'monospacestring') {
+ $self->_new_document_context($command_type);
+ _set_code_context($self, 1);
+ _set_string_context($self);
+ $arg_formatted->{$arg_type} = $self->_convert($arg,
$explanation);
+ #_unset_string_context($self);
+ _pop_code_context($self);
+ $self->_pop_document_context();
+ } elsif ($arg_type eq 'monospacetext') {
+ Texinfo::Convert::Text::set_options_code(
+ $self->{'convert_text_options'});
+ $arg_formatted->{$arg_type}
+ = Texinfo::Convert::Text::convert_to_text($arg,
+ $self->{'convert_text_options'});
+ Texinfo::Convert::Text::reset_options_code(
+ $self->{'convert_text_options'});
+ } elsif ($arg_type eq 'filenametext') {
+
+ Texinfo::Convert::Text::set_options_code(
+ $self->{'convert_text_options'});
+ # Always use encoded characters for file names
+ Texinfo::Convert::Text::set_options_encoding_if_not_ascii($self,
+ $self->{'convert_text_options'});
+ $arg_formatted->{$arg_type}
+ = Texinfo::Convert::Text::convert_to_text($arg,
+ $self->{'convert_text_options'});
+ Texinfo::Convert::Text::reset_options_code(
+ $self->{'convert_text_options'});
+ Texinfo::Convert::Text::reset_options_encoding(
+ $self->{'convert_text_options'});
+ } elsif ($arg_type eq 'url') {
+ Texinfo::Convert::Text::set_options_code(
+ $self->{'convert_text_options'});
+ # set the encoding to UTF-8 to always have a string that
+ # is suitable for percent encoding.
+ Texinfo::Convert::Text::set_options_encoding(
+ $self->{'convert_text_options'}, 'utf-8');
+ $arg_formatted->{$arg_type}
+ = Texinfo::Convert::Text::convert_to_text($arg,
+ $self->{'convert_text_options'});
+ Texinfo::Convert::Text::reset_options_code(
+ $self->{'convert_text_options'});
+ Texinfo::Convert::Text::reset_options_encoding(
+ $self->{'convert_text_options'});
+ } elsif ($arg_type eq 'raw') {
+ _set_raw_context($self);
+ $arg_formatted->{$arg_type} = $self->_convert($arg,
$explanation);
+ _unset_raw_context($self);
}
- push @$args_formatted, $arg_formatted;
}
+ push @$args_formatted, $arg_formatted;
}
}
diff --git a/tp/Texinfo/XS/convert/convert_html.c
b/tp/Texinfo/XS/convert/convert_html.c
index e08d202f69..570ed76179 100644
--- a/tp/Texinfo/XS/convert/convert_html.c
+++ b/tp/Texinfo/XS/convert/convert_html.c
@@ -1345,6 +1345,7 @@ html_convert_tree_append (CONVERTER *self, const ELEMENT
*element,
|| cmd == CM_cartouche)
{
const ELEMENT_LIST *arguments_list;
+ size_t arg_idx;
if (element->e.c->contents.list[0]->type == ET_arguments_line)
arguments_list
@@ -1352,196 +1353,192 @@ html_convert_tree_append (CONVERTER *self, const
ELEMENT *element,
else
arguments_list = &element->e.c->contents;
- if (arguments_list)
- {
- size_t arg_idx;
- TEXT formatted_arg;
+ TEXT formatted_arg;
- text_init (&formatted_arg);
+ text_init (&formatted_arg);
- args_formatted = (HTML_ARGS_FORMATTED *)
- malloc (sizeof (HTML_ARGS_FORMATTED));
- args_formatted->number = arguments_list->number;
- args_formatted->args = (HTML_ARG_FORMATTED *)
- malloc (args_formatted->number * sizeof
(HTML_ARG_FORMATTED));
- memset (args_formatted->args, 0,
- args_formatted->number * sizeof (HTML_ARG_FORMATTED));
+ args_formatted = (HTML_ARGS_FORMATTED *)
+ malloc (sizeof (HTML_ARGS_FORMATTED));
+ args_formatted->number = arguments_list->number;
+ args_formatted->args = (HTML_ARG_FORMATTED *)
+ malloc (args_formatted->number * sizeof (HTML_ARG_FORMATTED));
+ memset (args_formatted->args, 0,
+ args_formatted->number * sizeof (HTML_ARG_FORMATTED));
- for (arg_idx = 0; arg_idx < arguments_list->number;
arg_idx++)
- {
- char *explanation;
- unsigned long arg_flags = 0;
- const ELEMENT *arg = arguments_list->list[arg_idx];
- HTML_ARG_FORMATTED *arg_formatted
- = &args_formatted->args[arg_idx];
+ for (arg_idx = 0; arg_idx < arguments_list->number; arg_idx++)
+ {
+ char *explanation;
+ unsigned long arg_flags = 0;
+ const ELEMENT *arg = arguments_list->list[arg_idx];
+ HTML_ARG_FORMATTED *arg_formatted
+ = &args_formatted->args[arg_idx];
- if (arg->e.c->contents.number <= 0)
- {
- continue;
- }
- /* NOTE that commands with F_AFT_none as only flag do not
- have their flag reset to F_AFT_normal here, such that
- their argument is not converter here */
- if (arg_idx < MAX_COMMAND_ARGS_NR
- /* could check html_command_args_flags[cmd].status,
- but it is probably faster not to */
- && html_command_args_flags[cmd].flags[arg_idx])
- arg_flags =
html_command_args_flags[cmd].flags[arg_idx];
- else
- arg_flags = F_AFT_normal;
+ if (arg->e.c->contents.number <= 0)
+ {
+ continue;
+ }
+ /* NOTE that commands with F_AFT_none as only flag do not
+ have their flag reset to F_AFT_normal here, such that
+ their argument is not converter here */
+ if (arg_idx < MAX_COMMAND_ARGS_NR
+ /* could check html_command_args_flags[cmd].status,
+ but it is probably faster not to */
+ && html_command_args_flags[cmd].flags[arg_idx])
+ arg_flags = html_command_args_flags[cmd].flags[arg_idx];
+ else
+ arg_flags = F_AFT_normal;
- arg_formatted->arg_tree = arg;
+ arg_formatted->arg_tree = arg;
- if (arg_flags & F_AFT_normal)
+ if (arg_flags & F_AFT_normal)
+ {
+ text_reset (&formatted_arg);
+ if (convert_to_latex)
{
- text_reset (&formatted_arg);
- if (convert_to_latex)
+ char *latex_content
+ = call_latex_convert_to_latex_math (self,
+ arg);
+ if (latex_content)
{
- char *latex_content
- = call_latex_convert_to_latex_math (self,
- arg);
- if (latex_content)
- {
- text_append (&formatted_arg, latex_content);
- free (latex_content);
- }
+ text_append (&formatted_arg, latex_content);
+ free (latex_content);
}
- else
- {
- xasprintf (&explanation, "%s A[%zu]normal",
- command_type.text, arg_idx);
- html_convert_tree_append (self, arg,
- &formatted_arg,
- explanation);
- free (explanation);
- }
- arg_formatted->formatted[AFT_type_normal]
- = strdup (formatted_arg.text);
}
- if (arg_flags & F_AFT_monospace)
+ else
{
- HTML_DOCUMENT_CONTEXT *top_document_ctx
- = html_top_document_context (self);
- text_reset (&formatted_arg);
- xasprintf (&explanation, "%s A[%zu]monospace",
- command_type.text, arg_idx);
- push_integer_stack_integer (
- &top_document_ctx->monospace, 1);
-
- html_convert_tree_append (self, arg, &formatted_arg,
+ xasprintf (&explanation, "%s A[%zu]normal",
+ command_type.text, arg_idx);
+ html_convert_tree_append (self, arg,
+ &formatted_arg,
explanation);
- pop_integer_stack
- (&top_document_ctx->monospace);
-
free (explanation);
- arg_formatted->formatted[AFT_type_monospace]
- = strdup (formatted_arg.text);
}
- if (arg_flags & F_AFT_string)
- {
- HTML_DOCUMENT_CONTEXT *string_document_ctx;
- text_reset (&formatted_arg);
- html_new_document_context (self, command_type.text,
- 0, 0);
- string_document_ctx = html_top_document_context
(self);
- string_document_ctx->string_ctx++;
-
- xasprintf (&explanation, "%s A[%zu]string",
- command_type.text, arg_idx);
- html_convert_tree_append (self, arg, &formatted_arg,
- explanation);
+ arg_formatted->formatted[AFT_type_normal]
+ = strdup (formatted_arg.text);
+ }
+ if (arg_flags & F_AFT_monospace)
+ {
+ HTML_DOCUMENT_CONTEXT *top_document_ctx
+ = html_top_document_context (self);
+ text_reset (&formatted_arg);
+ xasprintf (&explanation, "%s A[%zu]monospace",
+ command_type.text, arg_idx);
+ push_integer_stack_integer (
+ &top_document_ctx->monospace, 1);
+
+ html_convert_tree_append (self, arg, &formatted_arg,
+ explanation);
+ pop_integer_stack
+ (&top_document_ctx->monospace);
- free (explanation);
+ free (explanation);
+ arg_formatted->formatted[AFT_type_monospace]
+ = strdup (formatted_arg.text);
+ }
+ if (arg_flags & F_AFT_string)
+ {
+ HTML_DOCUMENT_CONTEXT *string_document_ctx;
+ text_reset (&formatted_arg);
+ html_new_document_context (self, command_type.text,
+ 0, 0);
+ string_document_ctx = html_top_document_context (self);
+ string_document_ctx->string_ctx++;
+
+ xasprintf (&explanation, "%s A[%zu]string",
+ command_type.text, arg_idx);
+ html_convert_tree_append (self, arg, &formatted_arg,
+ explanation);
- html_pop_document_context (self);
+ free (explanation);
- arg_formatted->formatted[AFT_type_string]
- = strdup (formatted_arg.text);
- }
- if (arg_flags & F_AFT_monospacestring)
- {
- HTML_DOCUMENT_CONTEXT *string_document_ctx;
- text_reset (&formatted_arg);
- html_new_document_context (self, command_type.text,
- 0, 0);
- string_document_ctx = html_top_document_context
(self);
- string_document_ctx->string_ctx++;
- push_integer_stack_integer (
- &string_document_ctx->monospace, 1);
- xasprintf (&explanation, "%s A[%zu]monospacestring",
- command_type.text, arg_idx);
- html_convert_tree_append (self, arg, &formatted_arg,
- explanation);
+ html_pop_document_context (self);
- free (explanation);
- pop_integer_stack
- (&string_document_ctx->monospace);
- html_pop_document_context (self);
- arg_formatted->formatted[AFT_type_monospacestring]
- = strdup (formatted_arg.text);
- }
- if (arg_flags & F_AFT_monospacetext)
- {
- char *text;
+ arg_formatted->formatted[AFT_type_string]
+ = strdup (formatted_arg.text);
+ }
+ if (arg_flags & F_AFT_monospacestring)
+ {
+ HTML_DOCUMENT_CONTEXT *string_document_ctx;
+ text_reset (&formatted_arg);
+ html_new_document_context (self, command_type.text,
+ 0, 0);
+ string_document_ctx = html_top_document_context (self);
+ string_document_ctx->string_ctx++;
+ push_integer_stack_integer (
+ &string_document_ctx->monospace, 1);
+ xasprintf (&explanation, "%s A[%zu]monospacestring",
+ command_type.text, arg_idx);
+ html_convert_tree_append (self, arg, &formatted_arg,
+ explanation);
- self->convert_text_options->code_state++;
- text = convert_to_text (arg,
- self->convert_text_options);
- self->convert_text_options->code_state--;
+ free (explanation);
+ pop_integer_stack
+ (&string_document_ctx->monospace);
+ html_pop_document_context (self);
+ arg_formatted->formatted[AFT_type_monospacestring]
+ = strdup (formatted_arg.text);
+ }
+ if (arg_flags & F_AFT_monospacetext)
+ {
+ char *text;
- arg_formatted->formatted[AFT_type_monospacetext]
- = text;
- }
- if (arg_flags & F_AFT_filenametext)
- {
- char *text;
- self->convert_text_options->code_state++;
- /* Always use encoded characters for file names */
- text_set_options_encoding_if_not_ascii (self,
+ self->convert_text_options->code_state++;
+ text = convert_to_text (arg,
self->convert_text_options);
- text = convert_to_text (arg,
- self->convert_text_options);
- text_reset_options_encoding
- (self->convert_text_options);
- self->convert_text_options->code_state--;
+ self->convert_text_options->code_state--;
- arg_formatted->formatted[AFT_type_filenametext] =
text;
- }
- if (arg_flags & F_AFT_url)
- {
- char *text;
- self->convert_text_options->code_state++;
- /* set the encoding to UTF-8 to always have a string that is
suitable
- for percent encoding. */
- text_set_options_encoding (
- self->convert_text_options, "utf-8");
- text = convert_to_text (arg,
- self->convert_text_options);
- text_reset_options_encoding
- (self->convert_text_options);
- self->convert_text_options->code_state--;
-
- arg_formatted->formatted[AFT_type_url] = text;
- }
- if (arg_flags & F_AFT_raw)
- {
- HTML_DOCUMENT_CONTEXT *top_document_ctx
- = html_top_document_context (self);
- text_reset (&formatted_arg);
- top_document_ctx->raw_ctx++;
- xasprintf (&explanation, "%s A[%zu]raw",
- command_type.text, arg_idx);
- html_convert_tree_append (self, arg, &formatted_arg,
- explanation);
+ arg_formatted->formatted[AFT_type_monospacetext]
+ = text;
+ }
+ if (arg_flags & F_AFT_filenametext)
+ {
+ char *text;
+ self->convert_text_options->code_state++;
+ /* Always use encoded characters for file names */
+ text_set_options_encoding_if_not_ascii (self,
+ self->convert_text_options);
+ text = convert_to_text (arg,
+ self->convert_text_options);
+ text_reset_options_encoding
+ (self->convert_text_options);
+ self->convert_text_options->code_state--;
+
+ arg_formatted->formatted[AFT_type_filenametext] = text;
+ }
+ if (arg_flags & F_AFT_url)
+ {
+ char *text;
+ self->convert_text_options->code_state++;
+ /* set the encoding to UTF-8 to always have a string that is suitable
+ for percent encoding. */
+ text_set_options_encoding (
+ self->convert_text_options, "utf-8");
+ text = convert_to_text (arg,
+ self->convert_text_options);
+ text_reset_options_encoding
+ (self->convert_text_options);
+ self->convert_text_options->code_state--;
+
+ arg_formatted->formatted[AFT_type_url] = text;
+ }
+ if (arg_flags & F_AFT_raw)
+ {
+ HTML_DOCUMENT_CONTEXT *top_document_ctx
+ = html_top_document_context (self);
+ text_reset (&formatted_arg);
+ top_document_ctx->raw_ctx++;
+ xasprintf (&explanation, "%s A[%zu]raw",
+ command_type.text, arg_idx);
+ html_convert_tree_append (self, arg, &formatted_arg,
+ explanation);
- free (explanation);
- top_document_ctx->raw_ctx--;
- arg_formatted->formatted[AFT_type_raw]
- = strdup (formatted_arg.text);
- }
+ free (explanation);
+ top_document_ctx->raw_ctx--;
+ arg_formatted->formatted[AFT_type_raw]
+ = strdup (formatted_arg.text);
}
- free (formatted_arg.text);
}
+ free (formatted_arg.text);
}
html_convert_command_update_context (self, data_cmd);