[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
branch master updated: * tp/Texinfo/Convert/HTML.pm (footnote_location_h
From: |
Patrice Dumas |
Subject: |
branch master updated: * tp/Texinfo/Convert/HTML.pm (footnote_location_href): rename $special_target as $footnote_location_target_info. |
Date: |
Thu, 07 Dec 2023 03:23:34 -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 6bcd2be74f * tp/Texinfo/Convert/HTML.pm (footnote_location_href):
rename $special_target as $footnote_location_target_info.
6bcd2be74f is described below
commit 6bcd2be74f88b3969fad003434df81f264f60981
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Thu Dec 7 09:23:23 2023 +0100
* tp/Texinfo/Convert/HTML.pm (footnote_location_href): rename
$special_target as $footnote_location_target_info.
* tp/Texinfo/Convert/HTML.pm (_default_format_heading_text): Avoid
intermediary variables.
* tp/Texinfo/Convert/HTML.pm (_get_copiable_anchor): Allow id to be 0.
* tp/Texinfo/XS/convert/convert_html.c (copiable_link_array)
(copiable_link_classes, get_copiable_anchor)
(html_default_format_heading_text, format_heading_text): implement
get_copiable_anchor and format_heading_text in C. Update callers of
call_formatting_function_format_heading_text to call
format_heading_text instead.
---
ChangeLog | 19 ++++-
tp/Texinfo/Convert/HTML.pm | 43 ++++++-----
tp/Texinfo/XS/convert/convert_html.c | 145 ++++++++++++++++++++++++++++-------
3 files changed, 161 insertions(+), 46 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 5271f403c7..b0e76b876a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,21 @@
-2023-12-06 Patrice Dumas <pertusus@free.fr>
+2023-12-07 Patrice Dumas <pertusus@free.fr>
+
+ * tp/Texinfo/Convert/HTML.pm (footnote_location_href): rename
+ $special_target as $footnote_location_target_info.
+
+ * tp/Texinfo/Convert/HTML.pm (_default_format_heading_text): Avoid
+ intermediary variables.
+
+ * tp/Texinfo/Convert/HTML.pm (_get_copiable_anchor): Allow id to be 0.
+
+ * tp/Texinfo/XS/convert/convert_html.c (copiable_link_array)
+ (copiable_link_classes, get_copiable_anchor)
+ (html_default_format_heading_text, format_heading_text): implement
+ get_copiable_anchor and format_heading_text in C. Update callers of
+ call_formatting_function_format_heading_text to call
+ format_heading_text instead.
+
+2023-12-07 Patrice Dumas <pertusus@free.fr>
* tp/Texinfo/Convert/HTML.pm (footnote_location_target): explicit
return undef.
diff --git a/tp/Texinfo/Convert/HTML.pm b/tp/Texinfo/Convert/HTML.pm
index 125c16e1e9..c56295cffb 100644
--- a/tp/Texinfo/Convert/HTML.pm
+++ b/tp/Texinfo/Convert/HTML.pm
@@ -1119,12 +1119,13 @@ sub footnote_location_href($$;$$$)
$source_filename = $self->{'current_filename'}
if (not defined($source_filename));
- my $special_target = _get_footnote_location_target($self, $command);
+ my $footnote_location_target_info
+ = _get_footnote_location_target($self, $command);
my $target = '';
if (defined($specified_target)) {
$target = $specified_target;
- } elsif (defined($special_target)) {
- $target = $special_target->{'target'};
+ } elsif (defined($footnote_location_target_info)) {
+ $target = $footnote_location_target_info->{'target'};
}
# In the default footnote formatting functions, which calls
# footnote_location_href, the target file is always known as the
@@ -1134,22 +1135,23 @@ sub footnote_location_href($$;$$$)
# @insertcopying for instance) as the file found just below may not be the
# correct one in such a case.
if (not defined($target_filename)) {
- if (defined($special_target) and defined($special_target->{'filename'})) {
- $target_filename = $special_target->{'filename'};
+ if (defined($footnote_location_target_info)
+ and defined($footnote_location_target_info->{'filename'})) {
+ $target_filename = $footnote_location_target_info->{'filename'};
} else {
# in contrast with command_filename() we find the location holding
# the @footnote command, not the footnote element with footnotes
my ($root_element, $root_command)
= $self->_html_get_tree_root_element($command);
if (defined($root_element)) {
- if (not defined($special_target)) {
+ if (not defined($footnote_location_target_info)) {
$self->{'special_targets'}->{'footnote_location'}->{$command} = {};
- $special_target
+ $footnote_location_target_info
= $self->{'special_targets'}->{'footnote_location'}->{$command};
}
- $special_target->{'filename'}
+ $footnote_location_target_info->{'filename'}
= $root_element->{'unit_filename'};
- $target_filename = $special_target->{'filename'};
+ $target_filename = $footnote_location_target_info->{'filename'};
}
}
}
@@ -3822,25 +3824,30 @@ sub _default_format_heading_text($$$$$;$$$)
} elsif ($level > $self->get_conf('MAX_HEADER_LEVEL')) {
$level = $self->get_conf('MAX_HEADER_LEVEL');
}
- my $id_str = '';
+
+ my $result = $self->html_attribute_class("h$level", $classes);
+
if (defined($id)) {
- $id_str = " id=\"$id\"";
+ $result .= " id=\"$id\"";
# The ID of this heading is likely the point the user would prefer being
# linked to over the $target, since that's where they would be seeing a
# copiable anchor.
$target = $id;
}
- my $inside = $text;
+ $result .= '>';
+
if (defined $target && $self->get_conf('COPIABLE_LINKS')) {
# Span-wrap this anchor, so that the existing span:hover a.copiable-link
# rule applies.
- $inside = "<span>$text";
- $inside .= $self->_get_copiable_anchor($target);
- $inside .= '</span>';
+ $result .= "<span>$text";
+ $result .= $self->_get_copiable_anchor($target);
+ $result .= '</span>';
+ } else {
+ $result .= $text;
}
- my $result = $self->html_attribute_class("h$level", $classes)
- ."${id_str}>$inside</h$level>";
+ $result .= "</h$level>";
+
# titlefont appears inline in text, so no end of line is
# added. The end of line should be added by the user if needed.
$result .= "\n" unless (defined($cmdname) and $cmdname eq 'titlefont');
@@ -7324,7 +7331,7 @@ sub _convert_def_line_type($$$$)
sub _get_copiable_anchor {
my ($self, $id) = @_;
my $result = '';
- if ($id and $self->get_conf('COPIABLE_LINKS')) {
+ if (defined($id) and $id ne '' and $self->get_conf('COPIABLE_LINKS')) {
my $paragraph_symbol = $self->get_info('paragraph_symbol');
$result = $self->html_attribute_class('a', ['copiable-link'])
." href=\"#$id\"> $paragraph_symbol</a>";
diff --git a/tp/Texinfo/XS/convert/convert_html.c
b/tp/Texinfo/XS/convert/convert_html.c
index 29a9e2d0d4..005ab71110 100644
--- a/tp/Texinfo/XS/convert/convert_html.c
+++ b/tp/Texinfo/XS/convert/convert_html.c
@@ -4828,6 +4828,116 @@ format_separate_anchor (CONVERTER *self, const char *id,
}
}
+static char *copiable_link_array[] = {"copiable-link"};
+static const STRING_LIST copiable_link_classes = {copiable_link_array, 1, 1};
+
+static char *
+get_copiable_anchor (CONVERTER *self, const char *id)
+{
+ TEXT result;
+
+ text_init (&result);
+ text_append (&result, "");
+ if (id && strlen (id) && self->conf->COPIABLE_LINKS > 0)
+ {
+ char *attribute_class = html_attribute_class (self, "a",
+ &copiable_link_classes);
+ text_append (&result, attribute_class);
+ free (attribute_class);
+ text_printf (&result, " href=\"#%s\"> %s</a>",
+ id, self->special_character[SC_paragraph_symbol].string);
+ }
+ return result.text;
+}
+
+void
+html_default_format_heading_text (CONVERTER *self, const enum command_id cmd,
+ const STRING_LIST *classes, const char *text,
+ int level, const char *id, const ELEMENT *element,
+ const char *target, TEXT *result)
+{
+ int heading_level = level;
+ char *heading_html_element;
+ const char *heading_target;
+ if (!id && text[strspn (text, whitespace_chars)] == '\0')
+ return;
+
+ if (level < 1)
+ heading_level = 1;
+ else if (level > self->conf->MAX_HEADER_LEVEL)
+ heading_level = self->conf->MAX_HEADER_LEVEL;
+
+ xasprintf (&heading_html_element, "h%d", heading_level);
+
+ char *attribute_class
+ = html_attribute_class (self, heading_html_element, classes);
+ text_append (result, attribute_class);
+ free (heading_html_element);
+ free (attribute_class);
+
+ if (id)
+ {
+ text_printf (result, " id=\"%s\"", id);
+ /* The ID of this heading is likely the point the user would prefer being
+ linked to over the $target, since that's where they would be seeing a
+ copiable anchor. */
+ heading_target = id;
+ }
+ else
+ {
+ heading_target = target;
+ }
+
+ text_append_n (result, ">", 1);
+
+ if (heading_target && self->conf->COPIABLE_LINKS > 0)
+ {
+ char *copiable_anchor = get_copiable_anchor(self, heading_target);
+ text_append_n (result, "<span>", 6);
+ text_append (result, text);
+ text_append (result, copiable_anchor);
+ free (copiable_anchor);
+ text_append_n (result, "</span>", 7);
+ }
+ else
+ text_append (result, text);
+
+ text_printf (result, "</h%d>", heading_level);
+ if (cmd != CM_titlefont)
+ text_append_n (result, "\n", 1);
+ if (cmd == CM_part && self->conf->DEFAULT_RULE
+ && strlen (self->conf->DEFAULT_RULE))
+ {
+ text_append (result, self->conf->DEFAULT_RULE);
+ text_append_n (result, "\n", 1);
+ }
+}
+
+void
+format_heading_text (CONVERTER *self, const enum command_id cmd,
+ const STRING_LIST *classes, const char *text,
+ int level, const char *id, const ELEMENT *element,
+ const char *target, TEXT *result)
+
+{
+ if (self->formatting_references[FR_format_heading_text].status
+ == FRS_status_default_set)
+ {
+ html_default_format_heading_text (self, cmd, classes, text,
+ level, id, element, target, result);
+ }
+ else
+ {
+ char *heading_text
+ = call_formatting_function_format_heading_text (self,
+ builtin_command_name (cmd),
+ classes, text,
+ level, id, element, target);
+ text_append (result, heading_text);
+ free (heading_text);
+ }
+}
+
FORMATTED_BUTTON_INFO *
format_button (CONVERTER *self,
const BUTTON_SPECIFICATION *button,
@@ -5267,7 +5377,6 @@ default_format_footnotes_segment (CONVERTER *self, TEXT
*result)
ELEMENT *footnote_heading_tree;
char *footnote_heading;
int level;
- char *formatted_heading;
TEXT foot_lines;
text_init (&foot_lines);
@@ -5321,16 +5430,11 @@ default_format_footnotes_segment (CONVERTER *self, TEXT
*result)
add_string (class, classes);
free (class);
- formatted_heading
- = call_formatting_function_format_heading_text (self, 0, classes,
- footnote_heading,
- level, 0, 0, 0);
+ format_heading_text (self, 0, classes, footnote_heading, level, 0, 0, 0,
+ result);
destroy_strings_list (classes);
- text_append (result, formatted_heading);
text_append_n (result, "\n", 1);
- free (formatted_heading);
-
if (footnote_heading_tree)
free (footnote_heading);
@@ -5437,7 +5541,6 @@ contents_inline_element (CONVERTER *self, const enum
command_id cmd,
if (cmd_variety_index.cmd == cmd)
{
char *heading = 0;
- char *formatted_heading;
TEXT result;
STRING_LIST *classes;
char *class_base;
@@ -5500,15 +5603,13 @@ contents_inline_element (CONVERTER *self, const enum
command_id cmd,
if (!heading)
heading = strdup ("");
- formatted_heading
- = call_formatting_function_format_heading_text (self, 0,
classes,
- heading, self->conf->CHAPTER_HEADER_LEVEL, 0, 0,
0);
+ format_heading_text (self, 0, classes, heading,
+ self->conf->CHAPTER_HEADER_LEVEL,
+ 0, 0, 0, &result);
destroy_strings_list (classes);
free (heading);
- text_append (&result, formatted_heading);
- free (formatted_heading);
text_append_n (&result, "\n", 1);
text_append (&result, content);
@@ -5999,14 +6100,10 @@ convert_heading_command (CONVERTER *self, const enum
command_id cmd,
}
else
{
- char *formatted_heading
- = call_formatting_function_format_heading_text (self,
- builtin_command_name (level_corrected_cmd),
+ format_heading_text (self, level_corrected_cmd,
heading_classes, heading,
heading_level + self->conf->CHAPTER_HEADER_LEVEL -1,
- heading_id, element, element_id);
- text_append (result, formatted_heading);
- free (formatted_heading);
+ heading_id, element, element_id, result);
}
destroy_strings_list (heading_classes);
}
@@ -6247,7 +6344,6 @@ convert_special_unit_type (CONVERTER *self,
size_t count_in_file = 0;
int level;
char *formatted_footer;
- char *formatted_heading;
if (html_in_string (self))
return;
@@ -6330,16 +6426,11 @@ convert_special_unit_type (CONVERTER *self,
add_string (class, classes);
free (class);
- formatted_heading
- = call_formatting_function_format_heading_text (self, 0, classes, heading,
- level, 0, 0, 0);
+ format_heading_text (self, 0, classes, heading, level, 0, 0, 0, result);
free (heading);
destroy_strings_list (classes);
- text_append (result, formatted_heading);
text_append_n (result, "\n", 1);
- free (formatted_heading);
-
text_append (result, special_unit_body.text);
free (special_unit_body.text);
text_append (result, "</div>");
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- branch master updated: * tp/Texinfo/Convert/HTML.pm (footnote_location_href): rename $special_target as $footnote_location_target_info.,
Patrice Dumas <=