[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[no subject]
From: |
Patrice Dumas |
Date: |
Fri, 22 Dec 2023 04:30:04 -0500 (EST) |
branch: master
commit 874ce125243fb9c0971f952717f4ef7c08c96134
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Fri Dec 22 10:07:17 2023 +0100
* tp/Texinfo/XS/convert/get_html_perl_info.c
(html_converter_initialize_sv): increment
converter->no_arg_formatted_cmd.number only if there was no error on
the command and it is not undef.
* tp/Texinfo/XS/convert/convert_html.c (html_free_converter),
tp/Texinfo/XS/convert/get_html_perl_info.c
(html_converter_initialize_sv), tp/Texinfo/XS/main/converter_types.h
(CONVERTER): add style_formatted_cmd, the list of style formatted
commands, set and free associated data fully.
* tp/Texinfo/XS/convert/convert_html.c (convert_style_command)
(convert_indicateurl_command, commands_internal_conversion_table)
(html_converter_initialize): implement convert_style_command and
convert_indicateurl_command.
---
ChangeLog | 18 +++
tp/Texinfo/XS/convert/convert_html.c | 170 +++++++++++++++++++++++++++++
tp/Texinfo/XS/convert/get_html_perl_info.c | 21 +++-
tp/Texinfo/XS/main/converter_types.h | 1 +
4 files changed, 205 insertions(+), 5 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index cd3b445da8..89df93f0a5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,21 @@
+2023-12-22 Patrice Dumas <pertusus@free.fr>
+
+ * tp/Texinfo/XS/convert/get_html_perl_info.c
+ (html_converter_initialize_sv): increment
+ converter->no_arg_formatted_cmd.number only if there was no error on
+ the command and it is not undef.
+
+ * tp/Texinfo/XS/convert/convert_html.c (html_free_converter),
+ tp/Texinfo/XS/convert/get_html_perl_info.c
+ (html_converter_initialize_sv), tp/Texinfo/XS/main/converter_types.h
+ (CONVERTER): add style_formatted_cmd, the list of style formatted
+ commands, set and free associated data fully.
+
+ * tp/Texinfo/XS/convert/convert_html.c (convert_style_command)
+ (convert_indicateurl_command, commands_internal_conversion_table)
+ (html_converter_initialize): implement convert_style_command and
+ convert_indicateurl_command.
+
2023-12-21 Patrice Dumas <pertusus@free.fr>
* tp/Texinfo/XS/convert/convert_html.c
diff --git a/tp/Texinfo/XS/convert/convert_html.c
b/tp/Texinfo/XS/convert/convert_html.c
index a19a2d95de..f5e9082867 100644
--- a/tp/Texinfo/XS/convert/convert_html.c
+++ b/tp/Texinfo/XS/convert/convert_html.c
@@ -8029,6 +8029,91 @@ convert_today_command (CONVERTER *self, const enum
command_id cmd,
destroy_element_and_children (today_element);
}
+void
+convert_style_command (CONVERTER *self, const enum command_id cmd,
+ const ELEMENT *element,
+ const HTML_ARGS_FORMATTED *args_formatted,
+ const char *content, TEXT *result)
+{
+ enum command_id style_cmd = cmd;
+ HTML_COMMAND_CONVERSION *formatting_spec;
+
+ /* happens with bogus @-commands without argument, like @strong something */
+ if (!args_formatted || args_formatted->number <= 0
+ || !args_formatted->args[0].formatted[AFT_type_normal])
+ return;
+
+ if (html_in_string (self))
+ {
+ text_append (result, args_formatted->args[0].formatted[AFT_type_normal]);
+ return;
+ }
+
+ if (cmd == CM_kbd)
+ {
+ int status;
+ int code = lookup_extra_integer (element, "code", &status);
+ if (code > 0)
+ style_cmd = CM_code;
+ }
+
+ if (html_in_preformatted_context (self))
+ formatting_spec
+ = &self->html_command_conversion[style_cmd][HCC_type_preformatted];
+ else
+ formatting_spec
+ = &self->html_command_conversion[style_cmd][HCC_type_normal];
+
+ if (formatting_spec->element)
+ {
+ STRING_LIST *classes;
+ char *open;
+ size_t open_len;
+ classes = (STRING_LIST *) malloc (sizeof (STRING_LIST));
+ memset (classes, 0, sizeof (STRING_LIST));
+ add_string (builtin_command_name (style_cmd), classes);
+
+ if (style_cmd != cmd)
+ {
+ char *style_as_cmd;
+ xasprintf (&style_as_cmd, "as-%s-%s",
+ builtin_command_name (style_cmd),
+ builtin_command_name (cmd));
+ add_string (style_as_cmd, classes);
+ free (style_as_cmd);
+ }
+
+ if (formatting_spec->quote)
+ text_append (result, self->conf->OPEN_QUOTE_SYMBOL);
+
+ open
+ = html_attribute_class (self, formatting_spec->element, classes);
+ open_len = strlen (open);
+ destroy_strings_list (classes);
+
+ if (open_len > 0)
+ {
+ text_append (result, open);
+ text_append_n (result, ">", 1);
+ free (open);
+ }
+
+ text_append (result, args_formatted->args[0].formatted[AFT_type_normal]);
+
+ if (open_len > 0)
+ {
+ text_append_n (result, "</", 2);
+ text_append (result, formatting_spec->element);
+ text_append_n (result, ">", 1);
+ }
+
+ if (formatting_spec->quote)
+ text_append (result, self->conf->CLOSE_QUOTE_SYMBOL);
+ }
+ else
+ text_append (result, args_formatted->args[0].formatted[AFT_type_normal]);
+}
+
void
convert_w_command (CONVERTER *self, const enum command_id cmd,
const ELEMENT *element,
@@ -8047,6 +8132,43 @@ convert_w_command (CONVERTER *self, const enum
command_id cmd,
}
}
+void
+convert_indicateurl_command (CONVERTER *self, const enum command_id cmd,
+ const ELEMENT *element,
+ const HTML_ARGS_FORMATTED *args_formatted,
+ const char *content, TEXT *result)
+{
+ /* happens with bogus @-commands without argument, like @strong something */
+ if (!args_formatted || args_formatted->number <= 0
+ || !args_formatted->args[0].formatted[AFT_type_normal])
+ return;
+
+ text_append (result, self->conf->OPEN_QUOTE_SYMBOL);
+
+ if (!html_in_string (self))
+ {
+ char *attribute_class;
+ STRING_LIST *classes;
+ 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, "code", classes);
+ destroy_strings_list (classes);
+ text_append (result, attribute_class);
+ free (attribute_class);
+
+ text_append_n (result, ">", 1);
+
+ text_append (result, args_formatted->args[0].formatted[AFT_type_normal]);
+ text_append_n (result, "</code>", 7);
+ }
+ else
+ text_append (result, args_formatted->args[0].formatted[AFT_type_normal]);
+
+ text_append (result, self->conf->CLOSE_QUOTE_SYMBOL);
+}
+
void
convert_raw_command (CONVERTER *self, const enum command_id cmd,
const ELEMENT *element,
@@ -9495,6 +9617,11 @@ static COMMAND_INTERNAL_CONVERSION
commands_internal_conversion_table[] = {
{CM_w, &convert_w_command},
{CM_today, &convert_today_command},
+ /* note that this prevents indicateurl to be associated to
+ convert_style_command, otherwise it would be as it is in
+ self->style_formatted_cmd */
+ {CM_indicateurl, &convert_indicateurl_command},
+
{CM_contents, &convert_contents_command},
{CM_shortcontents, &convert_contents_command},
{CM_summarycontents, &convert_contents_command},
@@ -10413,6 +10540,35 @@ html_converter_initialize (CONVERTER *self)
}
}
+ /* all the commands in style_formatted_cmd are implemented in C.
+ It is not only the style commands, some others too. indicateurl
+ is on style_formatted_cmd, but is not set as it is already set
+ from commands_internal_conversion_table since it has a specific
+ formatting function */
+ if (self->style_formatted_cmd.number)
+ {
+ for (i = 0; i < self->style_formatted_cmd.number; i++)
+ {
+ enum command_id cmd = self->style_formatted_cmd.list[i];
+ COMMAND_CONVERSION_FUNCTION *command_conversion
+ = &self->command_conversion_function[cmd];
+ COMMAND_CONVERSION_FUNCTION *css_string_command_conversion
+ = &self->css_string_command_conversion_function[cmd];
+ if (command_conversion->status == FRS_status_default_set)
+ {
+ command_conversion->formatting_reference = 0;
+ command_conversion->status = FRS_status_internal;
+ command_conversion->command_conversion
+ = &convert_style_command;
+ }
+
+ css_string_command_conversion->formatting_reference = 0;
+ css_string_command_conversion->status = FRS_status_internal;
+ css_string_command_conversion->command_conversion
+ = &convert_style_command;
+ }
+ }
+
for (i = 0; commands_internal_open_table[i].command_open; i++)
{
enum command_id cmd = commands_internal_open_table[i].cmd;
@@ -10835,6 +10991,18 @@ html_free_converter (CONVERTER *self)
}
}
+ for (i = 0; i < self->style_formatted_cmd.number; i++)
+ {
+ enum command_id cmd = self->style_formatted_cmd.list[i];
+ enum conversion_context cctx;
+ for (cctx = 0; cctx < HCC_type_css_string+1; cctx++)
+ {
+ HTML_COMMAND_CONVERSION *format_spec
+ = &self->html_command_conversion[cmd][cctx];
+ free (format_spec->element);
+ }
+ }
+
for (i = 0; i < SUI_type_heading+1; i++)
{
int k;
@@ -10888,6 +11056,8 @@ html_free_converter (CONVERTER *self)
free (self->no_arg_formatted_cmd.list);
+ free (self->style_formatted_cmd.list);
+
free (self->pending_closes.stack);
free (self->pending_inline_content.stack);
diff --git a/tp/Texinfo/XS/convert/get_html_perl_info.c
b/tp/Texinfo/XS/convert/get_html_perl_info.c
index 84664d0959..db31ca7d8a 100644
--- a/tp/Texinfo/XS/convert/get_html_perl_info.c
+++ b/tp/Texinfo/XS/convert/get_html_perl_info.c
@@ -630,7 +630,7 @@ html_converter_initialize_sv (SV *converter_sv,
converter->no_arg_formatted_cmd.list = (enum command_id *)
malloc (hv_number * sizeof (enum command_id));
- converter->no_arg_formatted_cmd.number = hv_number;
+ converter->no_arg_formatted_cmd.number = 0;
for (i = 0; i < hv_number; i++)
{
@@ -643,8 +643,6 @@ html_converter_initialize_sv (SV *converter_sv,
HV *context_hv = (HV *)SvRV (context_sv);
enum command_id cmd = lookup_builtin_command (cmdname);
- converter->no_arg_formatted_cmd.list[i] = cmd;
-
if (!cmd)
fprintf (stderr, "ERROR: %s: no no arg command\n", cmdname);
else
@@ -652,6 +650,10 @@ html_converter_initialize_sv (SV *converter_sv,
I32 context_nr;
I32 j;
+ converter->no_arg_formatted_cmd.list[
+ converter->no_arg_formatted_cmd.number] = cmd;
+ converter->no_arg_formatted_cmd.number++;
+
context_nr = hv_iterinit (context_hv);
for (j = 0; j < context_nr; j++)
{
@@ -746,6 +748,10 @@ html_converter_initialize_sv (SV *converter_sv,
= (HV *)SvRV (*style_commands_formatting_sv);
hv_number = hv_iterinit (style_commands_formatting_hv);
+ converter->style_formatted_cmd.list = (enum command_id *)
+ malloc (hv_number * sizeof (enum command_id));
+ converter->style_formatted_cmd.number = 0;
+
for (i = 0; i < hv_number; i++)
{
char *cmdname;
@@ -763,6 +769,10 @@ html_converter_initialize_sv (SV *converter_sv,
I32 context_nr;
I32 j;
+ converter->style_formatted_cmd.list[
+ converter->style_formatted_cmd.number] = cmd;
+ converter->style_formatted_cmd.number++;
+
context_nr = hv_iterinit (context_hv);
for (j = 0; j < context_nr; j++)
{
@@ -809,15 +819,16 @@ html_converter_initialize_sv (SV *converter_sv,
&key, &retlen);
if (!strcmp (key, "element"))
{
- /* TODO add when it is used, and free
char *tmp_spec
= (char *) SvPVutf8_nolen (spec_sv);
format_spec->element = strdup (tmp_spec);
- */
}
else if (!strcmp (key, "quote"))
format_spec->quote = SvIV (spec_sv);
}
+ /*
+ fprintf (stderr, "HHH %d %d %s %d %d %s %d %s\n", i,
cmd, cmdname, j, context_idx, context_name, format_spec->quote,
format_spec->element);
+ */
}
}
}
diff --git a/tp/Texinfo/XS/main/converter_types.h
b/tp/Texinfo/XS/main/converter_types.h
index 05afce8d97..5d6d8cef76 100644
--- a/tp/Texinfo/XS/main/converter_types.h
+++ b/tp/Texinfo/XS/main/converter_types.h
@@ -677,6 +677,7 @@ typedef struct CONVERTER {
/* HTML specific */
/* set for a converter */
COMMAND_ID_LIST no_arg_formatted_cmd;
+ COMMAND_ID_LIST style_formatted_cmd;
int code_types[TXI_TREE_TYPES_NUMBER];
char *pre_class_types[TXI_TREE_TYPES_NUMBER];
int upper_case[BUILTIN_CMD_NUMBER];