texinfo-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

branch master updated: in HTML associate node without section to followi


From: Patrice Dumas
Subject: branch master updated: in HTML associate node without section to following heading command
Date: Wed, 26 Jul 2023 08:23:10 -0400

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 c7c7b6ce36 in HTML associate node without section to following heading 
command
c7c7b6ce36 is described below

commit c7c7b6ce369ea79870a6d4bf40d3b17d0e0757c3
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Wed Jul 26 14:23:00 2023 +0200

    in HTML associate node without section to following heading command
    
    * tp/Texinfo/Convert/HTML.pm (%defaults, _convert_heading_command),
    NEWS, doc/texinfo.texi (HTML Customization Variables),
    tp/Texinfo/Common.pm (@variable_string_settables),
    tp/Texinfo/Convert/Utils.pm (find_root_command_next_heading_command):
    add find_root_command_next_heading_command() to return a heading
    command found before contents that could be formatted.  Use that
    in HTML heading formating such as not to output a heading if there
    is a node not associated to sectioning command but followed by
    a @*heading command.  Use USE_NEXT_HEADING_FOR_LONE_NODE to customize
    that, set in the default case.
    
    * tp/Makefile.tres, tp/t/html_tests.t (headings_after_lone_nodes):
    new test to test association of lone node with next @*heading command.
---
 ChangeLog                   | 18 +++++++++
 NEWS                        |  5 +++
 doc/texi2any_api.texi       |  3 +-
 doc/texinfo.texi            |  7 ++++
 tp/Makefile.tres            |  1 +
 tp/Texinfo/Common.pm        | 11 +++++-
 tp/Texinfo/Convert/HTML.pm  | 28 +++++++++++++-
 tp/Texinfo/Convert/Utils.pm | 93 +++++++++++++++++++++++++++++++++++++++++++++
 tp/t/html_tests.t           | 77 +++++++++++++++++++++++++++++++++++++
 9 files changed, 239 insertions(+), 4 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 62db8b2d64..49b0a35a06 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,21 @@
+2023-07-26  Patrice Dumas  <pertusus@free.fr>
+
+       in HTML associate node without section to following heading command
+
+       * tp/Texinfo/Convert/HTML.pm (%defaults, _convert_heading_command),
+       NEWS, doc/texinfo.texi (HTML Customization Variables),
+       tp/Texinfo/Common.pm (@variable_string_settables),
+       tp/Texinfo/Convert/Utils.pm (find_root_command_next_heading_command):
+       add find_root_command_next_heading_command() to return a heading
+       command found before contents that could be formatted.  Use that
+       in HTML heading formating such as not to output a heading if there
+       is a node not associated to sectioning command but followed by
+       a @*heading command.  Use USE_NEXT_HEADING_FOR_LONE_NODE to customize
+       that, set in the default case.
+
+       * tp/Makefile.tres, tp/t/html_tests.t (headings_after_lone_nodes):
+       new test to test association of lone node with next @*heading command.
+
 2023-07-25  Patrice Dumas  <pertusus@free.fr>
 
        * tp/Texinfo/Convert/HTML.pm (_default_format_navigation_panel): do
diff --git a/NEWS b/NEWS
index af3f3d8ed4..468bbb8bea 100644
--- a/NEWS
+++ b/NEWS
@@ -41,6 +41,11 @@ See the manual for detailed information.
     . Change @point expansion to U+22C6 in HTML Cross-references.
     . omit colons after index entries by default.  this can still be
       configured with INDEX_ENTRY_COLON.
+    . if a @node is not associated to a sectioning command but is
+      followed by a heading command not usually associated to nodes,
+      such as @heading, and this command appears before other formatted
+      contents, the heading command is assumed to supply the node heading.
+      This can be customized with USE_NEXT_HEADING_FOR_LONE_NODE.
     . add @example syntax highlighting as a texi2any extension.
  . Info output:
     . new variable ASCII_DASHES_AND_QUOTES, on by default,
diff --git a/doc/texi2any_api.texi b/doc/texi2any_api.texi
index a46e9fbe75..832e46d40e 100644
--- a/doc/texi2any_api.texi
+++ b/doc/texi2any_api.texi
@@ -3955,7 +3955,8 @@ formatting, such as @code{SPLIT}, @code{HEADERS}, 
@code{DEFAULT_RULE},
 
 The customization variables
 @code{CONTENTS_OUTPUT_LOCATION},
-@code{CHAPTER_HEADER_LEVEL}, @code{TOC_LINKS} and @code{FORMAT_MENU}
+@code{CHAPTER_HEADER_LEVEL}, @code{TOC_LINKS},
+@code{USE_NEXT_HEADING_FOR_LONE_NODE} and @code{FORMAT_MENU}
 may be used to change the sectioning commands conversion.
 @xref{HTML Customization Variables,,, texinfo, Texinfo}.
 
diff --git a/doc/texinfo.texi b/doc/texinfo.texi
index 51de13cb2d..28a1cadcb2 100644
--- a/doc/texinfo.texi
+++ b/doc/texinfo.texi
@@ -16799,6 +16799,13 @@ Use entities for doubled single-quote characters
 Generate @code{<link>} elements in the HTML @code{<head>}
 output; default true.
 
+@item USE_NEXT_HEADING_FOR_LONE_NODE
+If set, a node not associated to a sectioning command but
+followed by a heading command not usually associated to node
+such as @code{@@heading} before other formatted contents
+do not have its name output as a heading, under the assumption
+that the command found provides the heading.  Default true.
+
 @item USE_NODE_DIRECTIONS
 If true, use nodes to determine where next, up and prev
 link to in node headers.  If false, use sections.  If undefined, use
diff --git a/tp/Makefile.tres b/tp/Makefile.tres
index e9d931cd85..6efcfb59f4 100644
--- a/tp/Makefile.tres
+++ b/tp/Makefile.tres
@@ -622,6 +622,7 @@ test_files_generated_list = 
$(test_tap_files_generated_list) \
   t/results/html_tests/footnotestyle_separate_html_text_no_monolithic.pl \
   t/results/html_tests/footnotestyle_separate_late.pl \
   t/results/html_tests/footnotestyle_separate_late/res_html \
+  t/results/html_tests/headings_after_lone_nodes.pl \
   t/results/html_tests/html_in_copying.pl \
   t/results/html_tests/image_link_prefix.pl \
   t/results/html_tests/index_and_node_same_name.pl \
diff --git a/tp/Texinfo/Common.pm b/tp/Texinfo/Common.pm
index c208af2fe7..80bec30501 100644
--- a/tp/Texinfo/Common.pm
+++ b/tp/Texinfo/Common.pm
@@ -449,6 +449,7 @@ our @variable_string_settables = (
 'USE_ACCESSKEY',
 'USE_ISO',
 'USE_LINKS',
+'USE_NEXT_HEADING_FOR_LONE_NODE',
 'USE_NODES',
 'USE_NODE_DIRECTIONS',
 'USE_NUMERIC_ENTITY',
@@ -734,9 +735,10 @@ foreach my $command (
 }
 
 
-# used only in this file in a function,
 # brace commands that are not replaced with text.
-my %non_formatted_brace_commands;
+our %non_formatted_brace_commands;
+# FIXME add seealso, seeentry, sortas?  Not so important as they
+# are in within index commands.
 foreach my $non_formatted_brace_command ('anchor', 'shortcaption',
     'caption', 'hyphenation', 'errormsg') {
   $non_formatted_brace_commands{$non_formatted_brace_command} = 1;
@@ -2770,6 +2772,11 @@ X<C<%nobrace_symbol_text>>
 Values are ASCII representation of single character non-alphabetical commands
 without brace such as C<*> or C<:>.  The value may be an empty string.
 
+=item %non_formatted_brace_commands
+
+Brace commands that are not immediately replaced with text, such as
+C<anchor>, C<caption>, C<errormsg> and others.
+
 =item %small_block_associated_command
 X<C<%small_block_associated_command>>
 
diff --git a/tp/Texinfo/Convert/HTML.pm b/tp/Texinfo/Convert/HTML.pm
index dca4941883..27d4bfd759 100644
--- a/tp/Texinfo/Convert/HTML.pm
+++ b/tp/Texinfo/Convert/HTML.pm
@@ -1908,6 +1908,7 @@ my %defaults = (
   'TOP_FILE'              => 'index.html', # ignores EXTENSION
   'TOP_NODE_FILE_TARGET'  => 'index.html', # ignores EXTENSION
   'USE_ACCESSKEY'         => 1,
+  'USE_NEXT_HEADING_FOR_LONE_NODE' => 1,
   'USE_ISO'               => 1,
   'USE_LINKS'             => 1,
   'USE_NODES'             => 1,
@@ -4236,7 +4237,32 @@ sub _convert_heading_command($$$$$)
       if ($element->{'extra'}->{'normalized'} eq 'Top') {
         $heading_level = 0;
       } else {
-        $heading_level = 3;
+        my $use_next_heading = 0;
+        if ($self->get_conf('USE_NEXT_HEADING_FOR_LONE_NODE')) {
+          my $expanded_format_raw
+             = $self->shared_conversion_state('expanded_format_raw', {});
+          # if no format is expanded, the formats will be checked each time
+          # but this is very unlikely, as html is always expanded.
+          if (length(keys(%$expanded_format_raw)) == 0) {
+            foreach my $output_format_command
+                (keys(%Texinfo::Comon::texinfo_output_formats)) {
+              if ($self->is_format_expanded($output_format_command)) {
+                $expanded_format_raw->{$output_format_command} = 1;
+              }
+            }
+          }
+          my $next_heading
+            = Texinfo::Convert::Utils::find_root_command_next_heading_command(
+                     $element, $expanded_format_raw,
+                     ($self->get_conf('CONTENTS_OUTPUT_LOCATION') eq 
'inline'));
+          if ($next_heading) {
+            $use_next_heading = 1;
+          }
+        }
+        if (!$use_next_heading) {
+          # use node
+          $heading_level = 3;
+        }
       }
     }
   } elsif ($element->{'structure'}
diff --git a/tp/Texinfo/Convert/Utils.pm b/tp/Texinfo/Convert/Utils.pm
index 5ac23bf4d7..e17870a808 100644
--- a/tp/Texinfo/Convert/Utils.pm
+++ b/tp/Texinfo/Convert/Utils.pm
@@ -336,6 +336,84 @@ sub add_heading_number($$$;$)
   return $result;
 }
 
+# Similar to Texinfo::Common::is_content_empty
+sub find_root_command_next_heading_command($$;$$)
+{
+  my $root = shift;
+  my $expanded_format_raw = shift;
+  my $do_not_ignore_contents = shift;
+  my $do_not_ignore_index_entries = shift;
+
+  return undef if (!$root->{'contents'});
+
+  $expanded_format_raw = {} if (!defined($expanded_format_raw));
+
+  foreach my $content (@{$root->{'contents'}}) {
+    #print STDERR Texinfo::Common::debug_print_element($content)."\n";
+    if ($content->{'cmdname'}) {
+      if 
($Texinfo::Commands::sectioning_heading_commands{$content->{'cmdname'}}) {
+        #print STDERR "HEADING FOUND ASSOCIATED $content->{'cmdname'}\n";
+        return $content;
+      }
+      if ($content->{'type'} and $content->{'type'} eq 'index_entry_command') {
+        if ($do_not_ignore_index_entries) {
+          return undef;
+        } else {
+          next;
+        }
+      }
+      if (exists($Texinfo::Commands::line_commands{$content->{'cmdname'}})) {
+        if ($Texinfo::Commands::formatted_line_commands{$content->{'cmdname'}}
+            or 
$Texinfo::Commands::formattable_line_commands{$content->{'cmdname'}}
+            or ($do_not_ignore_contents
+                and ($content->{'cmdname'} eq 'contents'
+                     or $content->{'cmdname'} eq 'shortcontents'
+                     or $content->{'cmdname'} eq 'summarycontents'))) {
+          return undef;
+        } else {
+          next;
+        }
+      } elsif 
(exists($Texinfo::Commands::nobrace_commands{$content->{'cmdname'}})) {
+        if 
($Texinfo::Commands::formatted_nobrace_commands{$content->{'cmdname'}}) {
+          return undef;
+        } else {
+          next;
+        }
+      } elsif 
(exists($Texinfo::Commands::block_commands{$content->{'cmdname'}})) {
+        if 
($Texinfo::Commands::non_formatted_block_commands{$content->{'cmdname'}}
+            or $Texinfo::Commands::block_commands{$content->{'cmdname'}} eq 
'region'
+            # ignored conditional
+            or $Texinfo::Commands::block_commands{$content->{'cmdname'}} eq 
'conditional'
+            or ($Texinfo::Commands::block_commands{$content->{'cmdname'}} eq 
'format_raw'
+                and !$expanded_format_raw->{$content->{'cmdname'}})) {
+          next;
+        } else {
+          return undef;
+        }
+      # brace commands
+      } else {
+        if 
($Texinfo::Common::non_formatted_brace_commands{$content->{'cmdname'}}) {
+          next;
+        } else {
+          return undef;
+        }
+      }
+    }
+    if ($content->{'type'}) {
+      if ($content->{'type'} eq 'paragraph') {
+        return undef;
+      }
+    }
+    # normally should not happen at the top level as text at top
+    # level should only contain spaces (empty lines, text before
+    # paragraphs).
+    if ($content->{'text'} and $content->{'text'} =~ /\S/) {
+      return undef;
+    }
+  }
+  return undef;
+}
+
 # this requires a converter argument
 sub encoded_output_file_name($$)
 {
@@ -512,6 +590,21 @@ normally a text element with one or two letter, and an 
array reference
 containing the accent commands nested in I<$element> (including
 I<$element>).
 
+=item $heading_element = find_root_command_next_heading_command($element, 
$expanded_format_raw, $do_not_ignore_contents, $do_not_ignore_index_entries)
+
+Return an heading element found in the I<$element> contents if it
+appears before contents that could be formatted.  I<$expanded_format_raw>
+is a hash reference with raw output formats (html, docbook, xml...) as
+keys, associated value should be set for expanded raw output formats.
+I<$do_not_ignore_contents> is optional.  If set, C<@contents> and
+C<@shortcontents> are considered to be formatted.
+I<$do_not_ignore_index_entries> is optional.  If set, index entries
+are considered to be formatted.
+
+Only heading elements corresponding to C<@heading>, C<@subheading> and similar
+@-commands that are not associated to nodes in general are found, not
+sectioning commands.
+
 =item $result = add_heading_number($converter, $heading_element, 
$heading_text, $do_number)
 X<C<add_heading_number>>
 
diff --git a/tp/t/html_tests.t b/tp/t/html_tests.t
index 04b1131616..2e023df2d1 100644
--- a/tp/t/html_tests.t
+++ b/tp/t/html_tests.t
@@ -545,6 +545,83 @@ in <b>html</b> in copying ``
 @top top
 
 '],
+['headings_after_lone_nodes',
+'@node Top
+@top top
+
+@node chap
+@chapter Chap
+
+@node Qt
+@subheading heading Qt
+
+Some text
+
+@node Other
+
+@anchor{toto}
+
+@nodedescription Describe Other
+
+@c comment
+
+@contents
+
+@frenchspacing on
+
+@tex
+tex format raw
+@end tex
+
+@ignore
+in ignore
+@end ignore
+
+@iftex
+in iftex
+@end iftex
+
+@subsubheading Finally!
+
+@node Not associated
+
+Some para
+
+@heading should not be associated
+
+@node 2 not
+
+@quotation
+in quotation
+@end quotation
+
+@heading should not be associated
+
+@node 3 not
+
+@html
+in html
+@end html
+
+@heading should not be associated
+
+@node 4 not
+
+@sp 2
+
+@heading should not be associated
+
+@node 5 not
+
+@menu
+* subnode::
+@end menu
+
+@heading should not be associated
+
+@node subnode
+
+', {'FORMAT_MENU' => 'sectiontoc'},],
 ['mathjax_with_texinfo',
 $mathjax_with_texinfo, {}, {'HTML_MATH' => 'mathjax'}],
 ['mathjax_with_texinfo_enable_encoding',



reply via email to

[Prev in Thread] Current Thread [Next in Thread]