[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[no subject]
From: |
Gavin D. Smith |
Date: |
Tue, 27 Dec 2022 17:23:35 -0500 (EST) |
branch: master
commit cba3630bb98f2b817b1f52438fa16019bc19bc7d
Author: Arsen Arsenović <arsen@aarsen.me>
AuthorDate: Tue Dec 27 22:22:14 2022 +0000
Re-enable copyable anchors in HTML output
* tp/Texinfo/Common.pm (relate_index_entries_to_table_items_in_tree)
(%valid_tree_transformations): Implement
relate_index_entries_to_table_items, a transform that finds all
table terms and associates their indices with them, so that the
HTML backend generates a copyable anchor.
* tp/texi2any.pl: Invoke the new
relate_index_entries_to_table_items transform.
(%formats_table): Enable the relate_index_entries_to_table_items
transformation on HTML.
* tp/tests/indices/list-of-tests (index_entries_relate_to_item):
New test case.
* tp/tests/indices/index_entries_relate_to_item.texi: New test file.
---
ChangeLog | 18 ++++++
tp/Texinfo/Common.pm | 64 ++++++++++++++++++++++
tp/tests/indices/Makefile.am | 1 +
tp/tests/indices/list-of-tests | 2 +
.../indices_in_begin_tables_lists.html | 14 ++---
tp/texi2any.pl | 6 ++
6 files changed, 96 insertions(+), 9 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index d218a7ea6c..2ab4ff015b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,21 @@
+2022-12-27 Arsen Arsenović <arsen@aarsen.me>
+
+ Re-enable copyable anchors in HTML output
+
+ * tp/Texinfo/Common.pm (relate_index_entries_to_table_items_in_tree)
+ (%valid_tree_transformations): Implement
+ relate_index_entries_to_table_items, a transform that finds all
+ table terms and associates their indices with them, so that the
+ HTML backend generates a copyable anchor.
+
+ * tp/texi2any.pl: Invoke the new
+ relate_index_entries_to_table_items transform.
+ (%formats_table): Enable the relate_index_entries_to_table_items
+ transformation on HTML.
+ * tp/tests/indices/list-of-tests (index_entries_relate_to_item):
+ New test case.
+ * tp/tests/indices/index_entries_relate_to_item.texi: New test file.
+
2022-12-27 Gavin Smith <gavinsmith0123@gmail.com>
* doc/texinfo.tex (\definedummies, \indexnofonts):
diff --git a/tp/Texinfo/Common.pm b/tp/Texinfo/Common.pm
index 6683eb5c3f..ff56aa40cc 100644
--- a/tp/Texinfo/Common.pm
+++ b/tp/Texinfo/Common.pm
@@ -54,6 +54,7 @@ use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
collect_commands_in_tree
collect_commands_list_in_tree
move_index_entries_after_items_in_tree
+relate_index_entries_to_table_items_in_tree
protect_colon_in_tree
protect_comma_in_tree
protect_first_parenthesis
@@ -524,6 +525,7 @@ foreach my $output_format_command ('info', 'plaintext',
my %valid_tree_transformations;
foreach my $valid_transformation ('simple_menus',
'fill_gaps_in_sectioning', 'move_index_entries_after_items',
+ 'relate_index_entries_to_items',
'insert_nodes_for_sectioning_commands',
'complete_tree_nodes_menus', 'regenerate_master_menu',
'indent_menu_descriptions') {
@@ -2175,6 +2177,62 @@ sub move_index_entries_after_items_in_tree($)
return modify_tree($tree, \&_move_index_entries_after_items);
}
+# Locates all @tables in the tree, and relocates index entry groups to be
+# related to the @item that immediately follows them.
+sub _relate_index_entries_to_table_items_in($)
+{
+ my $table = shift;
+
+ return unless $table->{'contents'};
+
+ # For each table_term in $table->{'contents'}->[0], relate it's content's
+ # first index_entry_command to the term itself.
+ foreach my $table_entry (@{$table->{'contents'}}) {
+ next unless $table_entry->{'contents'}
+ and $table_entry->{'type'} eq 'table_entry';
+
+ # AFAIU, there's always a unique term in the first position in an entry's
+ # contents.
+ my $term = $table_entry->{'contents'}->[0];
+
+ # Now, to discover the related @?index and @item entries.
+ my ($item, $index);
+ foreach my $content (@{$term->{'contents'}}) {
+ if ($content->{'extra'}
+ and $content->{'extra'}->{'index_entry'}) {
+ $index = $content->{'extra'}->{'index_entry'} unless $index;
+ } elsif ($content->{'cmdname'} and $content->{'cmdname'} eq 'item') {
+ $item = $content unless $item;
+ }
+ # If we found both, no need to proceed;
+ last if $item and $index;
+ }
+
+ next unless $item and $index;
+ $index->{'entry_element'} = $item;
+ }
+}
+
+sub _relate_index_entries_to_table_items($$)
+{
+ my $type = shift;
+ my $current = shift;
+
+ return $current unless $current->{'cmdname'};
+
+ if ($current->{'cmdname'} eq 'table') {
+ _relate_index_entries_to_table_items_in($current);
+ }
+
+ return $current;
+}
+
+sub relate_index_entries_to_table_items_in_tree($)
+{
+ my $tree = shift;
+ return modify_tree($tree, \&_relate_index_entries_to_table_items);
+}
+
# Common to different module, but not meant to be used in user-defined
# codes.
#
@@ -2570,6 +2628,12 @@ In C<@enumerate> and C<@itemize> from the tree, move
index entries
appearing just before C<@item> after the C<@item>. Comment lines
between index entries are moved too.
+=item relate_index_entries_to_table_items_in_tree($tree)
+X<C<relate_index_entries_to_table_items_in_tree>>
+
+In tables, relates index entries preceding items with said item, by placing it
+inside the entry's C<entry_element>.
+
=item $normalized_name = normalize_top_node_name($node_string)
X<C<normalize_top_node_name>>
diff --git a/tp/tests/indices/Makefile.am b/tp/tests/indices/Makefile.am
index 2056d1eb53..e26e80580e 100644
--- a/tp/tests/indices/Makefile.am
+++ b/tp/tests/indices/Makefile.am
@@ -9,6 +9,7 @@ EXTRA_DIST = index_table.texi index_split.texi \
same_doc_nr_split_index_and_element.texi \
printindex_between_part_chapter.texi \
indices_in_begin_tables_lists.texi \
+ index_entries_relate_to_item.texi \
list-of-tests res_parser res_parser_info
DISTCLEANFILES = tests.log tests.out
diff --git a/tp/tests/indices/list-of-tests b/tp/tests/indices/list-of-tests
index 939ff799f1..7007de834b 100644
--- a/tp/tests/indices/list-of-tests
+++ b/tp/tests/indices/list-of-tests
@@ -24,3 +24,5 @@ index_table index_table.texi -c 'TEXI2HTML 1' --split chapter
indices_in_begin_tables_lists indices_in_begin_tables_lists.texi
indices_in_begin_tables_lists_latex indices_in_begin_tables_lists.texi --latex
+
+index_entries_relate_to_item index_entries_relate_to_item.texi --html
diff --git
a/tp/tests/indices/res_parser/indices_in_begin_tables_lists/indices_in_begin_tables_lists.html
b/tp/tests/indices/res_parser/indices_in_begin_tables_lists/indices_in_begin_tables_lists.html
index 592b37203f..b5c6eccc1a 100644
---
a/tp/tests/indices/res_parser/indices_in_begin_tables_lists/indices_in_begin_tables_lists.html
+++
b/tp/tests/indices/res_parser/indices_in_begin_tables_lists/indices_in_begin_tables_lists.html
@@ -142,8 +142,7 @@ enum
</dl>
<dl class="table">
-<dt><a class="index-entry-id" id="index-cindex-in-table"></a>
-<code class="code">abb</code></dt>
+<dt><a id='index-cindex-in-table'></a><span><code class="code">abb</code><a
class="copiable-link" href='#index-cindex-in-table'> ¶</a></span></dt>
<dd><p>l–ine
</p></dd>
</dl>
@@ -156,8 +155,7 @@ enum
</dl>
<dl class="table">
-<dt><a class="index-entry-id" id="index-samp-cindex-in-table"></a>
-‘<samp class="samp">asamp--bb</samp>’</dt>
+<dt><a id='index-samp-cindex-in-table'></a><span>‘<samp
class="samp">asamp--bb</samp>’<a class="copiable-link"
href='#index-samp-cindex-in-table'> ¶</a></span></dt>
<dd><p>l–ine samp
</p></dd>
</dl>
@@ -185,15 +183,13 @@ enum
</dl>
<dl class="table">
-<dt><a class="index-entry-id" id="index-cindex-after-line"></a>
-‘<samp class="samp">asamp--bb2</samp>’</dt>
+<dt><a id='index-cindex-after-line'></a><span>‘<samp
class="samp">asamp--bb2</samp>’<a class="copiable-link"
href='#index-cindex-after-line'> ¶</a></span></dt>
</dl>
<dl class="table">
-<dt><a class="index-entry-id" id="index-cindex-first"></a>
-<a class="index-entry-id" id="index-second"></a>
+<dt><a class="index-entry-id" id="index-second"></a>
<a class="index-entry-id" id="index-third"></a>
-‘<samp class="samp">asamp--bb2</samp>’</dt>
+<a id='index-cindex-first'></a><span>‘<samp
class="samp">asamp--bb2</samp>’<a class="copiable-link"
href='#index-cindex-first'> ¶</a></span></dt>
</dl>
<hr>
diff --git a/tp/texi2any.pl b/tp/texi2any.pl
index ae7d718dbd..8f19a88049 100755
--- a/tp/texi2any.pl
+++ b/tp/texi2any.pl
@@ -589,6 +589,7 @@ my %formats_table = (
'internal_links' => 1,
'simple_menu' => 1,
'move_index_entries_after_items' => 1,
+ 'relate_index_entries_to_table_items' => 1,
'no_warn_non_empty_parts' => 1,
'module' => 'Texinfo::Convert::HTML'
},
@@ -1483,6 +1484,11 @@ while(@input_files) {
next;
}
+ if
($formats_table{$converted_format}->{'relate_index_entries_to_table_items'}
+ or $tree_transformations{'relate_index_entries_to_table_items'}) {
+ Texinfo::Common::relate_index_entries_to_table_items_in_tree($tree);
+ }
+
if ($formats_table{$converted_format}->{'move_index_entries_after_items'}
or $tree_transformations{'move_index_entries_after_items'}) {
Texinfo::Common::move_index_entries_after_items_in_tree($tree);