[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[no subject]
From: |
Patrice Dumas |
Date: |
Fri, 8 Dec 2023 11:07:46 -0500 (EST) |
branch: master
commit d33c43894654cb435dbef475dbf4ec250f26137b
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Fri Dec 8 17:07:36 2023 +0100
* tp/Texinfo/XS/convert/convert_html.c
(get_associated_inline_content_number)
(html_associate_pending_formatted_inline_content)
(html_get_associated_formatted_inline_content)
(html_finalize_output_state), tp/Texinfo/XS/main/converter_types.h
(HTML_ASSOCIATED_INLINE_CONTENT): use a TEXT in
HTML_ASSOCIATED_INLINE_CONTENT to accumulate content, and allow the
same element to be found more than once when text appears.
---
ChangeLog | 17 +++-
tp/Texinfo/XS/convert/convert_html.c | 155 ++++++++++++++++++++++++-----------
tp/Texinfo/XS/main/converter_types.h | 2 +-
3 files changed, 120 insertions(+), 54 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index ecc0166f0d..f279e4996e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,8 +1,19 @@
2023-12-08 Patrice Dumas <pertusus@free.fr>
- * tp/ext/highlight_syntax.pm: do not call
- get_pending_formatted_inline_content at example opening if the
- code calling get_associated_formatted_inline_content will not be
+ * tp/Texinfo/XS/convert/convert_html.c
+ (get_associated_inline_content_number)
+ (html_associate_pending_formatted_inline_content)
+ (html_get_associated_formatted_inline_content)
+ (html_finalize_output_state), tp/Texinfo/XS/main/converter_types.h
+ (HTML_ASSOCIATED_INLINE_CONTENT): use a TEXT in
+ HTML_ASSOCIATED_INLINE_CONTENT to accumulate content, and allow the
+ same element to be found more than once when text appears.
+
+2023-12-08 Patrice Dumas <pertusus@free.fr>
+
+ * tp/ext/highlight_syntax.pm (highlight_open_inline_container_type):
+ do not call get_pending_formatted_inline_content at example opening if
+ the code calling get_associated_formatted_inline_content will not be
called for example conversion, to have a correct pairing of calls by
the preformatted element eventually formatted.
diff --git a/tp/Texinfo/XS/convert/convert_html.c
b/tp/Texinfo/XS/convert/convert_html.c
index b05af71f84..4f3c10406a 100644
--- a/tp/Texinfo/XS/convert/convert_html.c
+++ b/tp/Texinfo/XS/convert/convert_html.c
@@ -949,6 +949,29 @@ html_get_pending_formatted_inline_content (CONVERTER *self)
return strdup ("");
}
+static size_t
+get_associated_inline_content_number (
+ HTML_ASSOCIATED_INLINE_CONTENT_LIST *associated_content_list,
+ const ELEMENT *element, const void *hv)
+{
+ size_t i;
+ for (i = 0; i < associated_content_list->number; i++)
+ {
+ HTML_ASSOCIATED_INLINE_CONTENT *element_associated_content
+ = &associated_content_list->list[i];
+ if ((element && (element_associated_content->element == element
+ || (element->hv
+ && element_associated_content->hv == element->hv)))
+ || (hv && (element_associated_content->hv == hv
+ || (element_associated_content->element
+ && element_associated_content->element->hv == hv))))
+ {
+ return i +1;
+ }
+ }
+ return 0;
+}
+
/* API to associate inline content to an element, typically
paragraph or preformatted. Allows to associate the pending
content to the first inline element. */
@@ -961,38 +984,54 @@ html_associate_pending_formatted_inline_content
(CONVERTER *self,
{
HTML_ASSOCIATED_INLINE_CONTENT_LIST *associated_content_list
= &self->associated_inline_content;
- HTML_ASSOCIATED_INLINE_CONTENT *element_associated_content;
- size_t i;
- size_t element_associated_content_idx;
- int empty_slot = 0;
+ HTML_ASSOCIATED_INLINE_CONTENT *element_associated_content = 0;
+ size_t number = get_associated_inline_content_number
(associated_content_list,
+ element,
hv);
+ if (number > 0)
+ element_associated_content = &associated_content_list->list[number -1];
- for (i = 0; i < associated_content_list->number; i++)
+ if (!element_associated_content)
{
- if (associated_content_list->list[i].inline_content == 0)
- {
- empty_slot = 1;
- element_associated_content_idx = i;
- }
- }
+ size_t i;
+ int empty_slot = 0;
- if (!empty_slot)
- {
- if (associated_content_list->number >= associated_content_list->space)
+ for (i = 0; i < associated_content_list->number; i++)
{
- associated_content_list->list
- = realloc (associated_content_list->list,
- (associated_content_list->space += 5)
- * sizeof (HTML_ASSOCIATED_INLINE_CONTENT));
+ if (associated_content_list->list[i].inline_content.space == 0)
+ {
+ empty_slot = 1;
+ number = i +1;
+ }
}
- element_associated_content_idx = associated_content_list->number;
- associated_content_list->number++;
+ if (!empty_slot)
+ {
+ if (associated_content_list->number >=
associated_content_list->space)
+ {
+ associated_content_list->list
+ = realloc (associated_content_list->list,
+ (associated_content_list->space += 5)
+ * sizeof (HTML_ASSOCIATED_INLINE_CONTENT));
+ }
+ associated_content_list->number++;
+ number = associated_content_list->number;
+ }
+ element_associated_content
+ = &associated_content_list->list[number -1];
+ element_associated_content->element = element;
+ element_associated_content->hv = hv;
+ text_init (&element_associated_content->inline_content);
+ /*
+ fprintf (stderr, "NNN (%zu)\n", associated_content_list->number);
+ */
}
- element_associated_content
- = &associated_content_list->list[element_associated_content_idx];
- element_associated_content->element = element;
- element_associated_content->hv = hv;
- element_associated_content->inline_content = strdup (inline_content);
+ text_append (&element_associated_content->inline_content, inline_content);
+ /*
+ if (element)
+ fprintf (stderr, "RRR-EE %p -> %p %zu\n", element, element->hv, number);
+ if (hv)
+ fprintf (stderr, "RRR-PP %p %zu\n", hv, number);
+ */
}
/* hv is used when called from perl element when called from C */
@@ -1003,26 +1042,27 @@ html_get_associated_formatted_inline_content (CONVERTER
*self,
{
HTML_ASSOCIATED_INLINE_CONTENT_LIST *associated_content_list
= &self->associated_inline_content;
- size_t i;
- for (i = 0; i < associated_content_list->number; i++)
+ HTML_ASSOCIATED_INLINE_CONTENT *element_associated_content = 0;
+ size_t number = get_associated_inline_content_number
(associated_content_list,
+ element,
hv);
+ /*
+ if (element)
+ fprintf (stderr, "GGG-EE %p -> %p %zu (%zu)\n", element, element->hv,
number, associated_content_list->number);
+ if (hv)
+ fprintf (stderr, "GGG-PP %p %zu (%zu)\n", hv, number,
associated_content_list->number);
+ */
+ if (number > 0)
+ element_associated_content = &associated_content_list->list[number -1];
+
+ if (element_associated_content)
{
- HTML_ASSOCIATED_INLINE_CONTENT *element_associated_content
- = &associated_content_list->list[i];
- if ((element && (element_associated_content->element == element
- || (element->hv
- && element_associated_content->hv == element->hv)))
- || (hv && (element_associated_content->hv == hv
- || (element_associated_content->element
- && element_associated_content->element->hv == hv))))
- {
- char *result = element_associated_content->inline_content;
- if (i == associated_content_list->number -1)
- associated_content_list->number--;
- else
- memset (element_associated_content, 0,
- sizeof (HTML_ASSOCIATED_INLINE_CONTENT));
- return result;
- }
+ char *result = element_associated_content->inline_content.text;
+ if (number == associated_content_list->number)
+ associated_content_list->number--;
+ else
+ memset (element_associated_content, 0,
+ sizeof (HTML_ASSOCIATED_INLINE_CONTENT));
+ return result;
}
return strdup ("");
}
@@ -7431,13 +7471,28 @@ html_finalize_output_state (CONVERTER *self)
{
HTML_ASSOCIATED_INLINE_CONTENT *associated_content
= &self->associated_inline_content.list[i];
- if (associated_content->inline_content)
+ if (associated_content->inline_content.space > 0)
{
- char *inline_content = associated_content->inline_content;
- message_list_document_warn (&self->error_messages, self->conf,
- "associated inline content not used: '%s'",
- inline_content);
- free (associated_content->inline_content);
+ char *inline_content = associated_content->inline_content.text;
+ if (associated_content->element)
+ {
+ char *element_str
+ = print_element_debug (associated_content->element, 0);
+ message_list_document_warn (&self->error_messages, self->conf,
+ "left inline content associated to %s: '%s'", element_str,
+ inline_content);
+ free (element_str);
+ }
+ else if (associated_content->hv)
+ {
+ message_list_document_warn (&self->error_messages, self->conf,
+ "left inline content of %p: '%s'", associated_content->hv,
+ inline_content);
+ }
+ else
+ message_list_document_warn (&self->error_messages, self->conf,
+ "left inline content associated: '%s'", inline_content);
+ free (associated_content->inline_content.text);
}
}
self->associated_inline_content.number = 0;
diff --git a/tp/Texinfo/XS/main/converter_types.h
b/tp/Texinfo/XS/main/converter_types.h
index f4d2c0b54a..d8762f391d 100644
--- a/tp/Texinfo/XS/main/converter_types.h
+++ b/tp/Texinfo/XS/main/converter_types.h
@@ -569,7 +569,7 @@ typedef struct HTML_ASSOCIATED_INLINE_CONTENT {
/* perl element. This should be HV *hv,
but we don't want to include the Perl headers everywhere; */
const void *hv;
- char *inline_content;
+ TEXT inline_content;
} HTML_ASSOCIATED_INLINE_CONTENT;
typedef struct HTML_ASSOCIATED_INLINE_CONTENT_LIST {