[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[no subject]
From: |
Patrice Dumas |
Date: |
Sat, 2 Dec 2023 10:49:49 -0500 (EST) |
branch: master
commit c92b26cd8b9d15f219f213e67ba49add0122db65
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Fri Dec 1 23:58:53 2023 +0100
* tp/Texinfo/Convert/HTML.pm (default_commands_args): reorder to
have an arg formatting done in the same order in perl and C.
* tp/Texinfo/XS/convert/convert_html.c (default_commands_args):
use F_AFT_none as flag for commands that do not have flag set but
should not have their argument considered as normal.
* tp/Texinfo/Convert/HTML.pm (_debug_print_html_contexts, _convert),
tp/Texinfo/XS/convert/convert_html.c (debug_print_html_contexts)
(convert_to_html_internal): separate the code showing the contexts to
be able to use it for debugging.
* tp/Texinfo/XS/convert/convert_html.c (convert_w_command)
(commands_internal_conversion_table): implement and use
convert_w_command.
* tp/Texinfo/XS/convert/convert_html.c (open_quotation_command)
(commands_internal_open_table): implement and use
open_quotation_command.
* tp/Texinfo/XS/convert/convert_html.c (open_inline_container_type):
implement.
---
ChangeLog | 25 ++++
tp/Texinfo/Convert/HTML.pm | 31 +++--
tp/Texinfo/XS/convert/build_html_perl_state.c | 18 ++-
tp/Texinfo/XS/convert/convert_html.c | 174 ++++++++++++++++++--------
tp/Texinfo/XS/convert/convert_html.h | 1 +
5 files changed, 185 insertions(+), 64 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 76cf22da9b..3d5f850c21 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,28 @@
+2023-12-01 Patrice Dumas <pertusus@free.fr>
+
+ * tp/Texinfo/Convert/HTML.pm (default_commands_args): reorder to
+ have an arg formatting done in the same order in perl and C.
+
+ * tp/Texinfo/XS/convert/convert_html.c (default_commands_args):
+ use F_AFT_none as flag for commands that do not have flag set but
+ should not have their argument considered as normal.
+
+ * tp/Texinfo/Convert/HTML.pm (_debug_print_html_contexts, _convert),
+ tp/Texinfo/XS/convert/convert_html.c (debug_print_html_contexts)
+ (convert_to_html_internal): separate the code showing the contexts to
+ be able to use it for debugging.
+
+ * tp/Texinfo/XS/convert/convert_html.c (convert_w_command)
+ (commands_internal_conversion_table): implement and use
+ convert_w_command.
+
+ * tp/Texinfo/XS/convert/convert_html.c (open_quotation_command)
+ (commands_internal_open_table): implement and use
+ open_quotation_command.
+
+ * tp/Texinfo/XS/convert/convert_html.c (open_inline_container_type):
+ implement.
+
2023-12-01 Patrice Dumas <pertusus@free.fr>
* tp/Texinfo/XS/convert/convert_html.c (COMMAND_INTERNAL_CONVERSION)
diff --git a/tp/Texinfo/Convert/HTML.pm b/tp/Texinfo/Convert/HTML.pm
index ed14cf6814..c54b2f077e 100644
--- a/tp/Texinfo/Convert/HTML.pm
+++ b/tp/Texinfo/Convert/HTML.pm
@@ -2627,6 +2627,9 @@ my %default_code_types = (
);
# specification of arguments formatting
+# to obtain the same order of converting as in C, order for one argument
+# should be normal, monospace, string, monospacestring, monospacetext,
+# filenametext, url, raw
my %default_commands_args = (
'anchor' => [['monospacestring']],
'email' => [['url', 'monospacestring'], ['normal']],
@@ -2640,7 +2643,7 @@ my %default_commands_args = (
'pxref' => [['monospace'],['normal'],['normal'],['filenametext'],['normal']],
'ref' => [['monospace'],['normal'],['normal'],['filenametext'],['normal']],
'link' => [['monospace'],['normal'],['filenametext']],
- 'image' => [['url', 'filenametext',
'monospacestring'],['filenametext'],['filenametext'],['string',
'normal'],['filenametext']],
+ 'image' => [['monospacestring', 'filenametext',
'url'],['filenametext'],['filenametext'],['normal','string'],['filenametext']],
# FIXME shouldn't it better not to convert if later ignored?
# note that right now ignored argument are in elided empty types
# but this could change.
@@ -12334,6 +12337,18 @@ sub _convert_type_update_context($$)
}
}
+sub _debug_print_html_contexts($)
+{
+ my $self = shift;
+ my @document_contexts = map {defined($_->{'context'})
+ ? $_->{'context'}: 'UNDEF'}
+ @{$self->{'document_context'}};
+ my @contexts_names = map {defined($_->{'context_name'})
+ ? $_->{'context_name'}: 'UNDEF'}
+ @{$self->{'document_context'}->[-1]->{'formatting_context'}};
+ return "[".join('|',@document_contexts)."](".join('|',@contexts_names).")";
+}
+
# Convert tree element $ELEMENT, and return HTML text for the output files.
sub _convert($$;$);
sub _convert($$;$)
@@ -12361,14 +12376,8 @@ sub _convert($$;$)
if ($debug) {
$explanation = 'NO EXPLANATION' if (!defined($explanation));
- my @document_contexts = map {defined($_->{'context'})
- ? $_->{'context'}: 'UNDEF'}
- @{$self->{'document_context'}};
- my @contexts_names = map {defined($_->{'context_name'})
- ? $_->{'context_name'}: 'UNDEF'}
- @{$self->{'document_context'}->[-1]->{'formatting_context'}};
- print STDERR "ELEMENT($explanation) [".join('|',@document_contexts)
- ."](".join('|',@contexts_names)."), ->";
+ my $contexts_str = $self->_debug_print_html_contexts();
+ print STDERR "ELEMENT($explanation) ".$contexts_str.", ->";
print STDERR " cmd: $element->{'cmdname'}," if ($element->{'cmdname'});
print STDERR " type: $element->{'type'}" if ($element->{'type'});
my $text = $element->{'text'};
@@ -12490,6 +12499,10 @@ sub _convert($$;$)
push @$args_formatted, undef;
next;
}
+ # NOTE here commands with empty array reference in
+ # array reference associated to command in default_commands_args
+ # do not have $arg_spec reset to normal, such that their argument
+ # is not converter here
$arg_spec = ['normal'] if (!defined($arg_spec));
my $arg_formatted = {'tree' => $arg};
foreach my $arg_type (@$arg_spec) {
diff --git a/tp/Texinfo/XS/convert/build_html_perl_state.c
b/tp/Texinfo/XS/convert/build_html_perl_state.c
index 495187a2a5..dac3f351d4 100644
--- a/tp/Texinfo/XS/convert/build_html_perl_state.c
+++ b/tp/Texinfo/XS/convert/build_html_perl_state.c
@@ -834,9 +834,22 @@ build_html_formatting_state (CONVERTER *converter,
unsigned long flags)
/* remove obsolete document contexts in perl */
while (converter->document_contexts_to_pop)
{
+ /*
+ SV** top_context_sv = av_fetch(document_context_av,
+ top_document_context_idx, 0);
+ if (top_context_sv)
+ {
+ HV *top_context_hv = (HV *) SvRV (*top_context_sv);
+ SV **context_sv = hv_fetch (top_context_hv, "context",
+ strlen ("context"), 0);
+ char *context = (char *) SvPVutf8_nolen (*context_sv);
+ fprintf (stderr, "PLPOP (top %zu) ctx '%s'\n",
+ top_document_context_idx, context);
+ }
+ */
+ av_pop (document_context_av);
converter->document_contexts_to_pop--;
top_document_context_idx--;
- av_pop (document_context_av);
}
}
@@ -847,6 +860,9 @@ build_html_formatting_state (CONVERTER *converter, unsigned
long flags)
HTML_DOCUMENT_CONTEXT *document_context
= &converter->html_document_context.stack[i];
HV *document_context_hv = build_html_document_context
(document_context);
+ /*
+ fprintf (stderr, "PLPUSH ctx '%s'\n", document_context->context);
+ */
av_push (document_context_av, newRV_noinc ((SV *)
document_context_hv));
}
converter->document_context_change = 0;
diff --git a/tp/Texinfo/XS/convert/convert_html.c
b/tp/Texinfo/XS/convert/convert_html.c
index 7694dec5d7..73efa7d33c 100644
--- a/tp/Texinfo/XS/convert/convert_html.c
+++ b/tp/Texinfo/XS/convert/convert_html.c
@@ -145,7 +145,7 @@ CMD_VARIETY command_special_unit_variety[] = {
{0, 0},
};
-/* unused */
+/* used to set flags to non-zero with a flag that does nothing */
#define F_AFT_none 0x0001
#define F_AFT_normal 0x0002
@@ -196,11 +196,11 @@ typedef struct COMMAND_ID_ARGS_SPECIFICATION {
static COMMAND_ID_ARGS_SPECIFICATION default_commands_args[] = {
{CM_anchor, {F_AFT_monospacestring}},
{CM_email, {F_AFT_url | F_AFT_monospacestring, F_AFT_normal}},
- {CM_footnote, {0}},
- {CM_printindex, {0}},
+ {CM_footnote, {F_AFT_none}}, /* no flag */
+ {CM_printindex, {F_AFT_none}}, /* no flag */
{CM_uref, {F_AFT_url | F_AFT_monospacestring, F_AFT_normal, F_AFT_normal}},
{CM_url, {F_AFT_url | F_AFT_monospacestring, F_AFT_normal, F_AFT_normal}},
- {CM_sp, {0}},
+ {CM_sp, {F_AFT_none}}, /* no flag */
{CM_inforef, {F_AFT_monospace, F_AFT_normal, F_AFT_filenametext}},
{CM_xref, {F_AFT_monospace, F_AFT_normal, F_AFT_normal, F_AFT_filenametext,
F_AFT_normal}},
{CM_pxref, {F_AFT_monospace, F_AFT_normal, F_AFT_normal, F_AFT_filenametext,
F_AFT_normal}},
@@ -212,8 +212,8 @@ static COMMAND_ID_ARGS_SPECIFICATION
default_commands_args[] = {
{CM_inlineraw, {F_AFT_monospacetext, F_AFT_raw}},
{CM_inlineifclear, {F_AFT_monospacetext, F_AFT_normal}},
{CM_inlineifset, {F_AFT_monospacetext, F_AFT_normal}},
- {CM_item, {0}},
- {CM_itemx, {0}},
+ {CM_item, {F_AFT_none}}, /* no flag */
+ {CM_itemx, {F_AFT_none}}, /* no flag */
{CM_value, {F_AFT_monospacestring}},
{CM_abbr, {F_AFT_normal, F_AFT_string}},
{CM_acronym, {F_AFT_normal, F_AFT_string}},
@@ -3924,18 +3924,78 @@ convert_row_type (CONVERTER *self, const enum
element_type type,
}
}
+void
+convert_w_command (CONVERTER *self, const enum command_id cmd,
+ const ELEMENT *element,
+ const HTML_ARGS_FORMATTED *args_formatted,
+ const char *content, TEXT *result)
+{
+ if (args_formatted && args_formatted->number > 0)
+ {
+ if (args_formatted->args[0].formatted[AFT_type_normal])
+ text_append (result,
+ args_formatted->args[0].formatted[AFT_type_normal]);
+ }
+ if (!in_string (self))
+ {
+ text_append (result, "<!-- /@w -->");
+ }
+}
/* associate command to the C function implementing the conversion */
static COMMAND_INTERNAL_CONVERSION commands_internal_conversion_table[] = {
+ {CM_w, &convert_w_command},
{0, 0},
};
+void
+open_quotation_command (CONVERTER *self, const enum command_id cmd,
+ const ELEMENT *element, TEXT *result)
+{
+ char *cmdname = element_command_name (element);
+ char *formatted_quotation_arg_to_prepend = 0;
+ if (element->args.number > 0 && element->args.list[0]->contents.number > 0)
+ {
+ ELEMENT *tree;
+ char *explanation;
+ NAMED_STRING_ELEMENT_LIST *substrings
+ = new_named_string_element_list ();
+ ELEMENT *quotation_arg_copy = copy_tree (element->args.list[0]);
+ add_element_to_named_string_element_list (substrings,
+ "quotation_arg", quotation_arg_copy);
+ tree = html_gdt_tree ("@b{{quotation_arg}:} ", self->document,
+ self, substrings, 0, 0);
+ destroy_named_string_element_list (substrings);
+ xasprintf (&explanation, "open %s prepended arg", cmdname);
+ add_to_element_list (&self->tree_to_build, tree);
+ formatted_quotation_arg_to_prepend
+ = html_convert_tree (self, tree, explanation);
+ remove_element_from_list (&self->tree_to_build, tree);
+ destroy_element_and_children (tree);
+ free (explanation);
+ }
+ html_register_pending_formatted_inline_content (self, cmdname,
+ formatted_quotation_arg_to_prepend);
+ free (formatted_quotation_arg_to_prepend);
+}
+
+void
+open_inline_container_type (CONVERTER *self, const enum element_type type,
+ const ELEMENT *element, TEXT *result)
+{
+ char *pending_formatted = html_get_pending_formatted_inline_content (self);
+ if (pending_formatted)
+ {
+ html_associate_pending_formatted_inline_content (self, element, 0,
+ pending_formatted);
+ free (pending_formatted);
+ }
+}
+
/* associate command to the C function implementing the opening */
static COMMAND_INTERNAL_OPEN commands_internal_open_table[] = {
- /*
{CM_quotation, &open_quotation_command},
- {CM_small_quotation, &open_quotation_command},
- */
+ {CM_smallquotation, &open_quotation_command},
{0, 0},
};
@@ -3956,7 +4016,6 @@ static TYPE_INTERNAL_OPEN types_internal_open_table[] = {
{0, 0},
};
-
void
convert_unit_type (CONVERTER *self, const enum output_unit_type unit_type,
const OUTPUT_UNIT *output_unit, const char *content,
@@ -4160,9 +4219,7 @@ command_conversion_external (CONVERTER *self, const enum
command_id cmd,
const HTML_ARGS_FORMATTED *args_formatted,
const char *content, TEXT *result)
{
- /* TODO call a C function if status is FRS_status_default_set
- maybe putting function references in an array */
- /* FIXME XS specific debug message */
+ /* XS specific debug message */
/*
if (self->conf->DEBUG > 0)
fprintf (stderr, "DEBUG: command conversion %s '%s'\n",
@@ -4193,7 +4250,6 @@ type_conversion_external (CONVERTER *self, const enum
element_type type,
{
FORMATTING_REFERENCE *formatting_reference
= self->current_types_conversion_function[type].formatting_reference;
-
if (formatting_reference->status > 0)
call_types_conversion (self, type, formatting_reference,
element, content, result);
@@ -5504,6 +5560,49 @@ html_convert_type_update_context (CONVERTER *self, enum
element_type type)
#define ADD(x) text_append (result, x)
+static char *
+debug_print_html_contexts (CONVERTER *self)
+{
+ int i;
+ TEXT contexts_str;
+ text_init (&contexts_str);
+ text_append (&contexts_str, "[");
+ HTML_DOCUMENT_CONTEXT_STACK *document_context_stack
+ = &self->html_document_context;
+ HTML_DOCUMENT_CONTEXT *top_document_ctx
+ = html_top_document_context (self);
+ HTML_FORMATTING_CONTEXT_STACK *formatting_context_stack
+ = &top_document_ctx->formatting_context;
+
+ for (i = 0; i < document_context_stack->top; i++)
+ {
+ HTML_DOCUMENT_CONTEXT *document_context
+ = &document_context_stack->stack[i];
+ if (i != 0)
+ text_append (&contexts_str, "|");
+ if (document_context->context)
+ text_append (&contexts_str, document_context->context);
+ else
+ text_append (&contexts_str, "UNDEF");
+ }
+ text_append (&contexts_str, "](");
+
+ for (i = 0; i < formatting_context_stack->top; i++)
+ {
+ HTML_FORMATTING_CONTEXT *formatting_context
+ = &formatting_context_stack->stack[i];
+ if (i != 0)
+ text_append (&contexts_str, "|");
+ if (formatting_context->context_name)
+ text_append (&contexts_str, formatting_context->context_name);
+ else
+ text_append (&contexts_str, "UNDEF");
+
+ }
+ text_append (&contexts_str, ")");
+ return contexts_str.text;
+}
+
/* EXPLANATION is used for debugging */
void
convert_to_html_internal (CONVERTER *self, const ELEMENT *element,
@@ -5524,48 +5623,12 @@ convert_to_html_internal (CONVERTER *self, const
ELEMENT *element,
if (self->conf->DEBUG > 0)
{
- int i;
TEXT debug_str;
- TEXT contexts_str;
+ char *contexts_str = debug_print_html_contexts (self);
text_init (&debug_str);
- text_init (&contexts_str);
- text_append (&contexts_str, "[");
- HTML_DOCUMENT_CONTEXT_STACK *document_context_stack
- = &self->html_document_context;
- HTML_DOCUMENT_CONTEXT *top_document_ctx
- = html_top_document_context (self);
- HTML_FORMATTING_CONTEXT_STACK *formatting_context_stack
- = &top_document_ctx->formatting_context;
-
- for (i = 0; i < document_context_stack->top; i++)
- {
- HTML_DOCUMENT_CONTEXT *document_context
- = &document_context_stack->stack[i];
- if (i != 0)
- text_append (&contexts_str, "|");
- if (document_context->context)
- text_append (&contexts_str, document_context->context);
- else
- text_append (&contexts_str, "UNDEF");
- }
- text_append (&contexts_str, "](");
-
- for (i = 0; i < formatting_context_stack->top; i++)
- {
- HTML_FORMATTING_CONTEXT *formatting_context
- = &formatting_context_stack->stack[i];
- if (i != 0)
- text_append (&contexts_str, "|");
- if (formatting_context->context_name)
- text_append (&contexts_str, formatting_context->context_name);
- else
- text_append (&contexts_str, "UNDEF");
-
- }
- text_append (&contexts_str, ")");
text_printf (&debug_str, "XS|ELEMENT(%s) %s, ->", explanation,
- contexts_str.text);
- free (contexts_str.text);
+ contexts_str);
+ free (contexts_str);
if (command_name)
text_printf (&debug_str, " cmd: %s,", command_name);
if (element->type)
@@ -5642,7 +5705,7 @@ convert_to_html_internal (CONVERTER *self, const ELEMENT
*element,
&& element->type != ET_index_entry_command))
{
enum command_id data_cmd = element_builtin_data_cmd (element);
- /* FIXME XS only debug message */
+ /* XS only debug message */
/*
if (self->conf->DEBUG > 0)
fprintf (stderr, "COMMAND: %s %s\n",
@@ -5751,6 +5814,9 @@ convert_to_html_internal (CONVERTER *self, const ELEMENT
*element,
{
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 command_args_flags[cmd].status,
but it is probably faster not to */
diff --git a/tp/Texinfo/XS/convert/convert_html.h
b/tp/Texinfo/XS/convert/convert_html.h
index 6befce2a0e..8f1a5eacbb 100644
--- a/tp/Texinfo/XS/convert/convert_html.h
+++ b/tp/Texinfo/XS/convert/convert_html.h
@@ -102,4 +102,5 @@ char *html_convert_output (CONVERTER *self, const ELEMENT
*root,
void html_check_transfer_state_finalization (CONVERTER *self);
void html_free_converter (CONVERTER *self);
void html_destroy_files_source_info (FILE_SOURCE_INFO_LIST *files_source_info);
+
#endif