[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
branch master updated: * tp/Texinfo/Convert/Converter.pm (float_name_cap
From: |
Patrice Dumas |
Subject: |
branch master updated: * tp/Texinfo/Convert/Converter.pm (float_name_caption): rename $caption as $caption_element. Use $substrings variable. |
Date: |
Sun, 31 Dec 2023 10:12:05 -0500 |
This is an automated email from the git hooks/post-receive script.
pertusus pushed a commit to branch master
in repository texinfo.
The following commit(s) were added to refs/heads/master by this push:
new 6088c288c7 * tp/Texinfo/Convert/Converter.pm (float_name_caption):
rename $caption as $caption_element. Use $substrings variable.
6088c288c7 is described below
commit 6088c288c7a69f9310e6a6f9ece6a888f88245ef
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Sun Dec 31 16:12:04 2023 +0100
* tp/Texinfo/Convert/Converter.pm (float_name_caption): rename
$caption as $caption_element. Use $substrings variable.
* tp/Texinfo/Convert/HTML.pm (_convert_float_command): rename $caption
as $caption_element. Avoid using contents when an element can be
used. Reorder code, use less intermediate variables.
* tp/Texinfo/XS/convert/convert_html.c (convert_float_command)
(commands_internal_conversion_table),
tp/Texinfo/XS/convert/converter.c (float_name_caption),
tp/Texinfo/XS/convert/converter.h (FLOAT_CAPTION_PREPENDED_ELEMENT):
add float_name_caption, implement convert_float_command.
---
ChangeLog | 15 ++++
tp/Texinfo/Convert/Converter.pm | 63 ++++++-------
tp/Texinfo/Convert/HTML.pm | 51 +++++------
tp/Texinfo/XS/convert/convert_html.c | 170 +++++++++++++++++++++++++++++++++++
tp/Texinfo/XS/convert/converter.c | 75 ++++++++++++++++
tp/Texinfo/XS/convert/converter.h | 7 ++
6 files changed, 321 insertions(+), 60 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 75a94ad1e8..7b74050c0f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+2023-12-31 Patrice Dumas <pertusus@free.fr>
+
+ * tp/Texinfo/Convert/Converter.pm (float_name_caption): rename
+ $caption as $caption_element. Use $substrings variable.
+
+ * tp/Texinfo/Convert/HTML.pm (_convert_float_command): rename $caption
+ as $caption_element. Avoid using contents when an element can be
+ used. Reorder code, use less intermediate variables.
+
+ * tp/Texinfo/XS/convert/convert_html.c (convert_float_command)
+ (commands_internal_conversion_table),
+ tp/Texinfo/XS/convert/converter.c (float_name_caption),
+ tp/Texinfo/XS/convert/converter.h (FLOAT_CAPTION_PREPENDED_ELEMENT):
+ add float_name_caption, implement convert_float_command.
+
2023-12-31 Patrice Dumas <pertusus@free.fr>
* tp/Texinfo/XS/convert/convert_html.c (convert_menu_command)
diff --git a/tp/Texinfo/Convert/Converter.pm b/tp/Texinfo/Convert/Converter.pm
index 534aa0bbbd..a61ec41b1c 100644
--- a/tp/Texinfo/Convert/Converter.pm
+++ b/tp/Texinfo/Convert/Converter.pm
@@ -1384,63 +1384,56 @@ sub float_name_caption($$)
my $self = shift;
my $element = shift;
- my $caption;
+ my $caption_element;
if ($element->{'extra'} and $element->{'extra'}->{'caption'}) {
- $caption = $element->{'extra'}->{'caption'};
+ $caption_element = $element->{'extra'}->{'caption'};
} elsif ($element->{'extra'} and $element->{'extra'}->{'shortcaption'}) {
- $caption = $element->{'extra'}->{'shortcaption'};
+ $caption_element = $element->{'extra'}->{'shortcaption'};
}
#if ($self->get_conf('DEBUG')) {
# my $caption_texi =
- # Texinfo::Convert::Texinfo::convert_to_texinfo({ 'contents' =>
$caption->{'contents'}});
+ # Texinfo::Convert::Texinfo::convert_to_texinfo(
+ # { 'contents' => $caption_element->{'contents'}});
# print STDERR " CAPTION: $caption_texi\n";
#}
- my $type_element;
- if ($element->{'extra'}->{'float_type'} ne '') {
- $type_element = $element->{'args'}->[0];
+
+ my $substrings = {};
+
+ my $float_number_element;
+ if ($element->{'extra'}
+ and defined($element->{'extra'}->{'float_number'})) {
+ $float_number_element = {'text' => $element->{'extra'}->{'float_number'}};
+ $substrings->{'float_number'} = $float_number_element;
}
my $prepended;
- if ($type_element) {
- if ($caption) {
- if ($element->{'extra'}
- and defined($element->{'extra'}->{'float_number'})) {
+ if ($element->{'extra'} and defined($element->{'extra'}->{'float_type'})
+ and $element->{'extra'}->{'float_type'} ne '') {
+ $substrings->{'float_type'} = $element->{'args'}->[0];
+ if ($caption_element) {
+ if ($float_number_element) {
# TRANSLATORS: added before caption
- $prepended = $self->gdt('{float_type} {float_number}: ',
- {'float_type' => $type_element,
- 'float_number'
- => {'text' => $element->{'extra'}->{'float_number'}}});
+ $prepended = $self->gdt('{float_type} {float_number}: ', $substrings);
} else {
# TRANSLATORS: added before caption, no float label
- $prepended = $self->gdt('{float_type}: ',
- {'float_type' => $type_element});
+ $prepended = $self->gdt('{float_type}: ', $substrings);
}
} else {
- if ($element->{'extra'}
- and defined($element->{'extra'}->{'float_number'})) {
- $prepended = $self->gdt("{float_type} {float_number}",
- {'float_type' => $type_element,
- 'float_number'
- => {'text' => $element->{'extra'}->{'float_number'}}});
+ if ($float_number_element) {
+ $prepended = $self->gdt("{float_type} {float_number}", $substrings);
} else {
- $prepended = $self->gdt("{float_type}",
- {'float_type' => $type_element});
+ $prepended = $self->gdt("{float_type}", $substrings);
}
}
- } elsif ($element->{'extra'}
- and defined($element->{'extra'}->{'float_number'})) {
- if ($caption) {
+ } elsif ($float_number_element) {
+ if ($caption_element) {
# TRANSLATORS: added before caption, no float type
- $prepended = $self->gdt('{float_number}: ',
- {'float_number'
- => {'text' => $element->{'extra'}->{'float_number'}}});
+ $prepended = $self->gdt('{float_number}: ', $substrings);
} else {
- $prepended = $self->gdt("{float_number}",
- {'float_number'
- => {'text' => $element->{'extra'}->{'float_number'}}});
+ $prepended = $self->gdt("{float_number}", $substrings);
}
}
- return ($caption, $prepended);
+ return ($caption_element, $prepended);
}
# This is used when the formatted text has no comment nor new line, but
diff --git a/tp/Texinfo/Convert/HTML.pm b/tp/Texinfo/Convert/HTML.pm
index d472a21081..8ae88c599e 100644
--- a/tp/Texinfo/Convert/HTML.pm
+++ b/tp/Texinfo/Convert/HTML.pm
@@ -5437,12 +5437,9 @@ sub _convert_float_command($$$$$)
$content = '' if (!defined($content));
- my ($caption, $prepended)
+ my ($caption_element, $prepended)
= Texinfo::Convert::Converter::float_name_caption($self, $command);
- my $caption_command_name;
- if (defined($caption)) {
- $caption_command_name = $caption->{'cmdname'};
- }
+
if (in_string($self)) {
my $prepended_text;
if ($prepended) {
@@ -5452,23 +5449,30 @@ sub _convert_float_command($$$$$)
$prepended_text = '';
}
my $caption_text = '';
- if ($caption and $caption->{'args'}->[0]
- and $caption->{'args'}->[0]->{'contents'}) {
+ if ($caption_element and $caption_element->{'args'}->[0]
+ and $caption_element->{'args'}->[0]->{'contents'}) {
$caption_text = $self->convert_tree_new_formatting_context(
- {'contents' => $caption->{'args'}->[0]->{'contents'}},
- 'float caption');
+ $caption_element->{'args'}->[0], 'float caption');
}
return $prepended.$content.$caption_text;
}
+ my $caption_command_name;
+ if (defined($caption_element)) {
+ $caption_command_name = $caption_element->{'cmdname'};
+ }
+
+ my $result = $self->html_attribute_class('div', [$cmdname]);
+
my $id = $self->command_id($command);
- my $id_str = '';;
if (defined($id) and $id ne '') {
- $id_str = " id=\"$id\"";
+ $result .= " id=\"$id\"";
}
+ $result .= ">\n" . $content;
+
my $prepended_text;
- my $caption_text = '';
+ my $caption_text;
if ($prepended) {
# FIXME add a span with a class name for the prependend information
# if not empty?
@@ -5477,38 +5481,35 @@ sub _convert_float_command($$$$$)
'args' => [{'type' => 'brace_command_arg',
'contents' => [$prepended]}]},
'float number type');
- if ($caption) {
+ if ($caption_element) {
# register the converted prepended tree to be prepended to
# the first paragraph in caption formatting
$self->register_pending_formatted_inline_content($caption_command_name,
$prepended_text);
$caption_text = $self->convert_tree_new_formatting_context(
- $caption->{'args'}->[0], 'float caption');
+ $caption_element->{'args'}->[0], 'float caption');
my $cancelled_prepended
=
$self->cancel_pending_formatted_inline_content($caption_command_name);
+ # unset if prepended text is in caption, i.e. is not cancelled
$prepended_text = '' if (not defined($cancelled_prepended));
}
if ($prepended_text ne '') {
+ # prepended text is not empty and did not find its way in caption
$prepended_text = '<p>'.$prepended_text.'</p>';
}
- } else {
+ } elsif (defined($caption_element)) {
$caption_text = $self->convert_tree_new_formatting_context(
- $caption->{'args'}->[0], 'float caption')
- if (defined($caption));
+ $caption_element->{'args'}->[0], 'float caption');
}
- my $float_type_number_caption = '';
- if ($caption_text ne '') {
- $float_type_number_caption
- = $self->html_attribute_class('div', [$caption_command_name]). '>'
+ if (defined($caption_text) and $caption_text ne '') {
+ $result .= $self->html_attribute_class('div', [$caption_command_name]). '>'
.$caption_text.'</div>';
} elsif (defined($prepended) and $prepended_text ne '') {
- $float_type_number_caption
- = $self->html_attribute_class('div', ['type-number-float']). '>'
+ $result .= $self->html_attribute_class('div', ['type-number-float']). '>'
. $prepended_text .'</div>';
}
- return $self->html_attribute_class('div', [$cmdname]). "${id_str}>\n"
- . $content . $float_type_number_caption . '</div>';
+ return $result . '</div>';
}
$default_commands_conversion{'float'} = \&_convert_float_command;
diff --git a/tp/Texinfo/XS/convert/convert_html.c
b/tp/Texinfo/XS/convert/convert_html.c
index 8e4a714a39..88382426d4 100644
--- a/tp/Texinfo/XS/convert/convert_html.c
+++ b/tp/Texinfo/XS/convert/convert_html.c
@@ -10627,6 +10627,175 @@ convert_menu_command (CONVERTER *self, const enum
command_id cmd,
destroy_strings_list (classes);
}
+static char *type_number_float_array[] = {"type-number-float"};
+static const STRING_LIST type_number_float_classes
+ = {type_number_float_array, 1, 1};
+
+
+void
+convert_float_command (CONVERTER *self, const enum command_id cmd,
+ const ELEMENT *element,
+ const HTML_ARGS_FORMATTED *args_formatted,
+ const char *content, TEXT *result)
+{
+ char *attribute_class;
+ STRING_LIST *classes;
+
+ char *id;
+ char *prepended_text = 0;
+ char *caption_text = 0;
+ char *caption_command_name = 0;
+
+ ELEMENT *caption_element;
+ ELEMENT *prepended;
+ FLOAT_CAPTION_PREPENDED_ELEMENT *caption_prepended
+ = float_name_caption (self, element);
+
+ caption_element = caption_prepended->caption;
+ prepended = caption_prepended->prepended;
+
+ free (caption_prepended);
+
+ if (html_in_string (self))
+ {
+ if (prepended)
+ {
+ char *prepended_text;
+ add_to_element_list (&self->tree_to_build, prepended);
+ prepended_text
+ = convert_tree_new_formatting_context (self, prepended,
+ "float prepended", 0, 0, 0);
+ remove_element_from_list (&self->tree_to_build, prepended);
+ destroy_element_and_children (prepended);
+ if (prepended_text)
+ {
+ text_append (result, prepended_text);
+ free (prepended_text);
+ }
+ }
+ if (content)
+ text_append (result, content);
+
+ if (caption_element && caption_element->args.number > 0
+ && caption_element->args.list[0]->contents.number > 0)
+ {
+ char *caption_text
+ = convert_tree_new_formatting_context (self,
+ caption_element->args.list[0], "float caption", 0, 0, 0);
+ if (caption_text)
+ {
+ text_append (result, caption_text);
+ free (caption_text);
+ }
+ }
+ return;
+ }
+
+ if (caption_element)
+ caption_command_name = builtin_command_name (caption_element->cmd);
+
+ classes = (STRING_LIST *) malloc (sizeof (STRING_LIST));
+ memset (classes, 0, sizeof (STRING_LIST));
+ add_string (builtin_command_name (cmd), classes);
+
+ attribute_class = html_attribute_class (self, "div", classes);
+ text_append (result, attribute_class);
+ free (attribute_class);
+ clear_strings_list (classes);
+
+ id = html_command_id (self, element);
+ if (id && strlen (id))
+ text_printf (result, " id=\"%s\"", id);
+
+ text_append_n (result, ">\n", 2);
+ text_append (result, content);
+
+ if (prepended)
+ {
+ ELEMENT *strong_element = new_element (ET_NONE);
+ ELEMENT *args = new_element (ET_brace_command_arg);
+
+ strong_element->cmd = CM_strong;
+ add_to_element_args (strong_element, args);
+ add_to_element_contents (args, prepended);
+
+ add_to_element_list (&self->tree_to_build, strong_element);
+ prepended_text = convert_tree_new_formatting_context (self,
+ strong_element, "float number type", 0, 0, 0);
+ remove_element_from_list (&self->tree_to_build, strong_element);
+
+ destroy_element_and_children (strong_element);
+
+ if (caption_element)
+ {
+ char *cancelled_prepended;
+ /* register the converted prepended tree to be prepended to
+ the first paragraph in caption formatting */
+ if (prepended_text)
+ html_register_pending_formatted_inline_content (self,
+ caption_command_name, prepended_text);
+ caption_text = convert_tree_new_formatting_context (self,
+ caption_element->args.list[0], "float caption",
+ 0, 0, 0);
+ if (prepended_text)
+ {
+ cancelled_prepended
+ = html_cancel_pending_formatted_inline_content (self,
+ caption_command_name);
+ /* unset if prepended text is in caption, i.e. is not cancelled */
+ if (!cancelled_prepended)
+ {
+ free (prepended_text);
+ prepended_text = 0;
+ }
+ }
+ }
+ if (prepended_text && strlen (prepended_text))
+ {
+ /* prepended text is not empty and did not find its way in caption */
+ char *tmp;
+ xasprintf (&tmp, "<p>%s</p>", prepended_text);
+ free (prepended_text);
+ prepended_text = tmp;
+ }
+ }
+ else if (caption_element)
+ {
+ caption_text = convert_tree_new_formatting_context (self,
+ caption_element->args.list[0], "float caption",
+ 0, 0, 0);
+ }
+
+ if (caption_text && strlen (caption_text))
+ {
+ add_string (caption_command_name, classes);
+ attribute_class = html_attribute_class (self, "div", classes);
+ text_append (result, attribute_class);
+ free (attribute_class);
+
+ text_append_n (result, ">", 1);
+ text_append (result, caption_text);
+ text_append_n (result, "</div>", 6);
+ }
+ else if (prepended_text && strlen (prepended_text))
+ {
+ attribute_class = html_attribute_class (self, "div",
+ &type_number_float_classes);
+ text_append (result, attribute_class);
+ free (attribute_class);
+ text_append_n (result, ">", 1);
+ text_append (result, prepended_text);
+ text_append_n (result, "</div>", 6);
+ }
+
+ free (caption_text);
+ free (prepended_text);
+
+ text_append_n (result, "</div>", 6);
+
+ destroy_strings_list (classes);
+}
+
void
convert_xref_commands (CONVERTER *self, const enum command_id cmd,
const ELEMENT *element,
@@ -11486,6 +11655,7 @@ static COMMAND_INTERNAL_CONVERSION
commands_internal_conversion_table[] = {
{CM_group, &convert_command_simple_block},
{CM_menu, &convert_menu_command},
{CM_detailmenu, &convert_menu_command},
+ {CM_float, &convert_float_command},
{CM_verbatiminclude, &convert_verbatiminclude_command},
{CM_sp, &convert_sp_command},
diff --git a/tp/Texinfo/XS/convert/converter.c
b/tp/Texinfo/XS/convert/converter.c
index eaa64d0b32..f34f050764 100644
--- a/tp/Texinfo/XS/convert/converter.c
+++ b/tp/Texinfo/XS/convert/converter.c
@@ -349,6 +349,81 @@ float_type_number (CONVERTER *self, const ELEMENT *float_e)
return tree;
}
+FLOAT_CAPTION_PREPENDED_ELEMENT *
+float_name_caption (CONVERTER *self, const ELEMENT *float_e)
+{
+ ELEMENT *prepended = 0;
+ ELEMENT *type_element = 0;
+ FLOAT_CAPTION_PREPENDED_ELEMENT *result = (FLOAT_CAPTION_PREPENDED_ELEMENT *)
+ malloc (sizeof (FLOAT_CAPTION_PREPENDED_ELEMENT));
+ NAMED_STRING_ELEMENT_LIST *replaced_substrings
+ = new_named_string_element_list ();
+
+ char *float_type = lookup_extra_string (float_e, "float_type");
+ char *float_number = lookup_extra_string (float_e, "float_number");
+
+ ELEMENT *caption_element = lookup_extra_element (float_e, "caption");
+ if (!caption_element)
+ caption_element = lookup_extra_element (float_e, "shortcaption");
+
+ if (float_type && strlen (float_type))
+ type_element = float_e->args.list[0];
+
+ if (float_number)
+ {
+ ELEMENT *e_number = new_element (ET_NONE);
+ text_append (&e_number->text, float_number);
+ add_element_to_named_string_element_list (replaced_substrings,
+ "float_number", e_number);
+ }
+
+ if (type_element)
+ {
+ ELEMENT *type_element_copy = copy_tree (type_element);
+ add_element_to_named_string_element_list (replaced_substrings,
+ "float_type", type_element_copy);
+ if (caption_element)
+ {
+ if (float_number)
+ /* TRANSLATORS: added before caption */
+ prepended = gdt_tree ("{float_type} {float_number}: ",
+ self->document,
+ self->conf, replaced_substrings, 0, 0);
+ else
+ /* TRANSLATORS: added before caption, no float label */
+ prepended = gdt_tree ("{float_type}: ", self->document, self->conf,
+ replaced_substrings, 0, 0);
+ }
+ else
+ {
+ if (float_number)
+ prepended = gdt_tree ("{float_type} {float_number}",
+ self->document,
+ self->conf, replaced_substrings, 0, 0);
+ else
+ prepended = gdt_tree ("{float_type}", self->document, self->conf,
+ replaced_substrings, 0, 0);
+ }
+ }
+ else if (float_number)
+ {
+ if (caption_element)
+ /* TRANSLATORS: added before caption, no float type */
+ prepended = gdt_tree ("{float_number}: ", self->document, self->conf,
+ replaced_substrings, 0, 0);
+ else
+ prepended = gdt_tree ("{float_number}", self->document, self->conf,
+ replaced_substrings, 0, 0);
+ }
+
+ result->caption = caption_element;
+ result->prepended = prepended;
+
+ destroy_named_string_element_list (replaced_substrings);
+
+ return result;
+}
+
char *
convert_accents (CONVERTER *self, const ELEMENT *accent,
char *(*convert_tree)(CONVERTER *self, const ELEMENT *tree, char
*explanation),
diff --git a/tp/Texinfo/XS/convert/converter.h
b/tp/Texinfo/XS/convert/converter.h
index 79fe02e6e9..065189b313 100644
--- a/tp/Texinfo/XS/convert/converter.h
+++ b/tp/Texinfo/XS/convert/converter.h
@@ -68,6 +68,11 @@
} \
break;
+typedef struct FLOAT_CAPTION_PREPENDED_ELEMENT {
+ ELEMENT *caption;
+ ELEMENT *prepended;
+} FLOAT_CAPTION_PREPENDED_ELEMENT;
+
CONVERTER *retrieve_converter (int converter_descriptor);
size_t new_converter(void);
@@ -97,6 +102,8 @@ void free_comma_index_subentries_tree (ELEMENT_LIST
*element);
char *top_node_filename (CONVERTER *self, char *document_name);
ELEMENT *float_type_number (CONVERTER *self, const ELEMENT *float_e);
+FLOAT_CAPTION_PREPENDED_ELEMENT *float_name_caption (CONVERTER *self,
+ const ELEMENT *float_e);
void initialize_output_units_files (CONVERTER *self);
size_t set_output_unit_file (CONVERTER *self, OUTPUT_UNIT *output_unit,
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- branch master updated: * tp/Texinfo/Convert/Converter.pm (float_name_caption): rename $caption as $caption_element. Use $substrings variable.,
Patrice Dumas <=