texinfo-commits
[Top][All Lists]
Advanced

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

branch master updated: Treat spaces in @verb and @w differently in HTML


From: Gavin D. Smith
Subject: branch master updated: Treat spaces in @verb and @w differently in HTML
Date: Sat, 07 Jan 2023 16:23:46 -0500

This is an automated email from the git hooks/post-receive script.

gavin pushed a commit to branch master
in repository texinfo.

The following commit(s) were added to refs/heads/master by this push:
     new 5399b0d469 Treat spaces in @verb and @w differently in HTML
5399b0d469 is described below

commit 5399b0d469137144775f3cd5ec5f5bc530d88500
Author: Gavin Smith <gavinsmith0123@gmail.com>
AuthorDate: Sat Jan 7 21:23:36 2023 +0000

    Treat spaces in @verb and @w differently in HTML
    
    * tp/Texinfo/Convert/HTML.pm (_convert): Only use 'space_protected'
    stack for @verb.  Use new 'no_break' stack for @w.
    
    (_convert_text): Handle 'space_protected' and 'no_break' differently.
    For 'space_protected', convert newlines to <br> or <br/> and keep
    multiple spaces.  For 'no_break', treat newline as space and
    condense multiple spaces to one non-breaking space.
    
    (in_non_breakable_space): Check 'no_break' stack instead of
    'space_protected' stack.
    (in_space_protected): New function to check 'space_protected' stack.
    
    * doc/texi2any_api.texi (Text Formatting Context): Add documentation
    of in_space_protected.
    * tp/init/html32.pm (html32_convert_text): Call in_space_protected
    as well as in_non_breakable_space API functions.
---
 ChangeLog                                          | 21 ++++++++++++++++
 doc/texi2any_api.texi                              | 10 +++++++-
 tp/Texinfo/Convert/HTML.pm                         | 28 ++++++++++++++++++----
 tp/init/html32.pm                                  |  4 +++-
 .../converters_tests/spaces_in_empty_node_names.pl |  2 +-
 .../converters_tests/spaces_in_node_names.pl       |  4 ++--
 tp/t/results/coverage_braces/test_w.pl             | 10 ++++----
 tp/t/results/coverage_braces/verb_in_xref.pl       |  2 +-
 tp/t/results/menu/verb_in_menu_description.pl      |  2 +-
 tp/t/results/misc_commands/test_allowcodebreaks.pl |  2 +-
 .../formatting/res_parser/cpp_lines/cpp_lines.html |  2 +-
 11 files changed, 68 insertions(+), 19 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index d6e5933560..68f9df77af 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,24 @@
+2023-01-07  Gavin Smith  <gavinsmith0123@gmail.com>
+
+       Treat spaces in @verb and @w differently in HTML
+
+       * tp/Texinfo/Convert/HTML.pm (_convert): Only use 'space_protected'
+       stack for @verb.  Use new 'no_break' stack for @w.
+
+       (_convert_text): Handle 'space_protected' and 'no_break' differently.
+       For 'space_protected', convert newlines to <br> or <br/> and keep
+       multiple spaces.  For 'no_break', treat newline as space and
+       condense multiple spaces to one non-breaking space.
+
+       (in_non_breakable_space): Check 'no_break' stack instead of
+       'space_protected' stack.
+       (in_space_protected): New function to check 'space_protected' stack.
+
+       * doc/texi2any_api.texi (Text Formatting Context): Add documentation
+       of in_space_protected.
+       * tp/init/html32.pm (html32_convert_text): Call in_space_protected
+       as well as in_non_breakable_space API functions.
+
 2023-01-07  Gavin Smith  <gavinsmith0123@gmail.com>
 
        @backslashchar{} as \ in PDF bookmarks
diff --git a/doc/texi2any_api.texi b/doc/texi2any_api.texi
index 6b59ce9f30..8de57255cd 100644
--- a/doc/texi2any_api.texi
+++ b/doc/texi2any_api.texi
@@ -2596,7 +2596,15 @@ Return true if in upper-case context, corresponding to 
@code{@@sc}.
 @item non-breakable space
 
 @deftypefun {@var{$in_non_breakable_space} =} 
@var{$converter}->in_non_breakable_space ()
-Return true if in non-breakable space context, corresponding to @code{@@w}.
+Return true if in context where line breaks are forbidden, corresponding
+to @code{@@w}.
+@end deftypefun
+
+@item space protected
+
+@deftypefun {@var{$in_space_protected} =} @var{$converter}->in_space_protected 
()
+Return true if in context where space and newline characters are kept,
+corresponding to @code{@@verb}.
 @end deftypefun
 @end table
 
diff --git a/tp/Texinfo/Convert/HTML.pm b/tp/Texinfo/Convert/HTML.pm
index 44a140a2d9..5013adf699 100644
--- a/tp/Texinfo/Convert/HTML.pm
+++ b/tp/Texinfo/Convert/HTML.pm
@@ -507,6 +507,13 @@ sub in_upper_case($)
 }
 
 sub in_non_breakable_space($)
+{
+  my $self = shift;
+  return $self->{'document_context'}->[-1]->{'formatting_context'}->[-1]
+                                                         ->{'no_break'};
+}
+
+sub in_space_protected($)
 {
   my $self = shift;
   return $self->{'document_context'}->[-1]->{'formatting_context'}->[-1]
@@ -6247,8 +6254,14 @@ sub _convert_text($$$)
 
   # API info: in_non_breakable_space() API code conforming would be:
   #if ($self->in_non_breakable_space()) {
-  if ($formatting_context->{'space_protected'}) {
-    $text .= $self->get_info('non_breaking_space') if (chomp($text));
+  if ($formatting_context->{'no_break'}) {
+    my $non_breaking_space = $self->get_info('non_breaking_space');
+    $text =~ s/\n/ /g;
+    $text =~ s/ +/$non_breaking_space/g;
+  # API info: in_space_protected() API code conforming would be:
+  #} elsif ($self->in_space_protected()) {
+  } elsif ($formatting_context->{'space_protected'}) {
+    $text .= $self->{'line_break_element'} if (chomp($text));
     # Protect spaces within text
     my $non_breaking_space = $self->get_info('non_breaking_space');
     $text =~ s/ /$non_breaking_space/g;
@@ -11220,9 +11233,12 @@ sub _convert($$;$)
         $self->{'document_context'}->[-1]->{'math'}++;
         $convert_to_latex = 1 if ($self->get_conf('CONVERT_TO_LATEX_IN_MATH'));
       }
-      if ($command_name eq 'w' or $command_name eq 'verb') {
+      if ($command_name eq 'verb') {
         $self->{'document_context'}->[-1]->{'formatting_context'}->[-1]
                                                         
->{'space_protected'}++;
+      } elsif ($command_name eq 'w') {
+        $self->{'document_context'}->[-1]->{'formatting_context'}->[-1]
+                                                   ->{'no_break'}++;
       }
       my $result = '';
       if (defined($self->{'commands_open'}->{$command_name})) {
@@ -11340,10 +11356,12 @@ sub _convert($$;$)
       } elsif ($math_commands{$command_name}) {
         $self->{'document_context'}->[-1]->{'math'}--;
       }
-      if ($command_name eq 'w'
-                or $command_name eq 'verb') {
+      if ($command_name eq 'verb') {
         $self->{'document_context'}->[-1]->{'formatting_context'}->[-1]
                                                    ->{'space_protected'}--;
+      } elsif ($command_name eq 'w') {
+        $self->{'document_context'}->[-1]->{'formatting_context'}->[-1]
+                                                   ->{'no_break'}--;
       }
       if ($format_raw_commands{$command_name}) {
         $self->{'document_context'}->[-1]->{'raw'}--;
diff --git a/tp/init/html32.pm b/tp/init/html32.pm
index 50b7b941de..3519d2ce9b 100644
--- a/tp/init/html32.pm
+++ b/tp/init/html32.pm
@@ -165,7 +165,9 @@ sub html32_convert_text($$$$)
     $text =~ s/--/-/g;
     $text =~ s/\x{1F}/--/g;
   }
-  if (!$self->in_preformatted() and $self->in_non_breakable_space()) {
+  if (!$self->in_preformatted()
+      and ($self->in_non_breakable_space()
+             or $self->in_space_protected())) {
     $text .= '&nbsp;' if (chomp($text));
     $text =~ s/ /&nbsp;/g;
   }
diff --git a/tp/t/results/converters_tests/spaces_in_empty_node_names.pl 
b/tp/t/results/converters_tests/spaces_in_empty_node_names.pl
index 75887950ed..6bf81780a9 100644
--- a/tp/t/results/converters_tests/spaces_in_empty_node_names.pl
+++ b/tp/t/results/converters_tests/spaces_in_empty_node_names.pl
@@ -818,7 +818,7 @@ 
$result_converted{'html_text'}->{'spaces_in_empty_node_names'} = '<a class="node
 </p>
 <p>&lsquo;<code class="verb">&nbsp;&nbsp;</code>&rsquo;
 </p>
-<p>&lsquo;&nbsp;&nbsp;<!-- /@w -->&rsquo;
+<p>&lsquo;&nbsp;<!-- /@w -->&rsquo;
 </p>';
 
 
diff --git a/tp/t/results/converters_tests/spaces_in_node_names.pl 
b/tp/t/results/converters_tests/spaces_in_node_names.pl
index 0aba70557c..333573349f 100644
--- a/tp/t/results/converters_tests/spaces_in_node_names.pl
+++ b/tp/t/results/converters_tests/spaces_in_node_names.pl
@@ -908,13 +908,13 @@ $result_converted{'html_text'}->{'spaces_in_node_names'} 
= '<a class="node-id" i
 <p>
  &nbsp; </p>
 </div>
-<h4 class="node">c&nbsp;&nbsp;<!-- /@w --></h4>
+<h4 class="node">c&nbsp;<!-- /@w --></h4>
 
 <p><a class="ref" href="#a-">a&nbsp;&nbsp;</a>
 </p>
 <p><a class="ref" href="#b-">b<code class="verb">&nbsp;&nbsp;</code></a>
 </p>
-<p><a class="ref" href="#c-">c&nbsp;&nbsp;<!-- /@w --></a>
+<p><a class="ref" href="#c-">c&nbsp;<!-- /@w --></a>
 </p>';
 
 
diff --git a/tp/t/results/coverage_braces/test_w.pl 
b/tp/t/results/coverage_braces/test_w.pl
index 6d2da830af..357e143e2e 100644
--- a/tp/t/results/coverage_braces/test_w.pl
+++ b/tp/t/results/coverage_braces/test_w.pl
@@ -722,21 +722,21 @@ $result_converted{'html_text'}->{'test_w'} = 
'<p>aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
 <p><!-- /@w -->
 </p>
-<p>&nbsp;a&nbsp;rr&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ggg.<!-- /@w -->
+<p>&nbsp;a&nbsp;rr&nbsp;&nbsp;ggg.<!-- /@w -->
 </p>
 <p>AA<!-- /@w -->bbb.
 </p>
 <p>FFd<!-- /@w -->nnn.
 </p>
-<p>aa&nbsp;&nbsp;f&nbsp;&nbsp;f<!-- /@w -->ggg.
+<p>aa&nbsp;f&nbsp;f<!-- /@w -->ggg.
 </p>
-<p>aa2&nbsp;&nbsp;f&nbsp;&nbsp;f&nbsp;<!-- /@w -->ggg2.
+<p>aa2&nbsp;f&nbsp;f&nbsp;<!-- /@w -->ggg2.
 </p>
 
-<p>aa3 &nbsp;&nbsp;f&nbsp;&nbsp;f&nbsp;<!-- /@w -->ggg3.
+<p>aa3 &nbsp;f&nbsp;f&nbsp;<!-- /@w -->ggg3.
 </p>
 
-<p>aa4 &nbsp;&nbsp;f&nbsp;&nbsp;f&nbsp;<!-- /@w --> ggg4.
+<p>aa4 &nbsp;f&nbsp;f&nbsp;<!-- /@w --> ggg4.
 </p>
 <p>aa5 <!-- /@w --> ggg5.
 </p>
diff --git a/tp/t/results/coverage_braces/verb_in_xref.pl 
b/tp/t/results/coverage_braces/verb_in_xref.pl
index 8a7e8759e8..3100d0031d 100644
--- a/tp/t/results/coverage_braces/verb_in_xref.pl
+++ b/tp/t/results/coverage_braces/verb_in_xref.pl
@@ -200,7 +200,7 @@ ggg : Top.
 
 $result_converted{'html_text'}->{'verb_in_xref'} = '<h1 class="node" 
id="Top">Top</h1>
 
-<p>See <a class="xref" href="#Top"><code 
class="verb">with&nbsp;verb&nbsp;&nbsp;ggg&nbsp;</code></a>.
+<p>See <a class="xref" href="#Top"><code 
class="verb">with<br>verb<br><br>ggg&nbsp;</code></a>.
 </p>';
 
 
diff --git a/tp/t/results/menu/verb_in_menu_description.pl 
b/tp/t/results/menu/verb_in_menu_description.pl
index 5a5fb5e3e8..50b9cd17e9 100644
--- a/tp/t/results/menu/verb_in_menu_description.pl
+++ b/tp/t/results/menu/verb_in_menu_description.pl
@@ -391,7 +391,7 @@ th.menu-comment {text-align:left}
 
 <table class="menu" border="0" cellspacing="0">
 <tr><td class="menu-entry-destination">&bull; <a href="manual.html#Top" 
accesskey="1">(manual)</a>:</td><td>&nbsp;&nbsp;</td><td 
class="menu-entry-description">
-<code class="verb">&nbsp;in&nbsp;verb&nbsp;&nbsp;</code>
+<code class="verb">&nbsp;in&nbsp;verb<br><br></code>
 </td></tr>
 <tr><th class="menu-comment" colspan="3"><pre 
class="menu-comment-preformatted">
 
diff --git a/tp/t/results/misc_commands/test_allowcodebreaks.pl 
b/tp/t/results/misc_commands/test_allowcodebreaks.pl
index ea729f9098..21986136e1 100644
--- a/tp/t/results/misc_commands/test_allowcodebreaks.pl
+++ b/tp/t/results/misc_commands/test_allowcodebreaks.pl
@@ -2103,7 +2103,7 @@ anc-hor<a class="anchor" id="A-node1"></a></samp>&rsquo;
 </pre></div>
 
 <p>In w:
-Out&nbsp;of&nbsp;code&nbsp;&mdash;&nbsp;out-of-code.&nbsp;<code 
class="code">1aaa</code>&nbsp;<code class="code">2aaa-</code>&nbsp;<code 
class="code">-3bbb</code>&nbsp;<code 
class="code">4aaa-bbb</code>&nbsp;&nbsp;<code 
class="code">&nbsp;5aaa-bb</code>&nbsp;<code 
class="code">6aaa-bb&nbsp;</code>&nbsp;<code 
class="code">ccc&nbsp;7aaa-bbb</code>&nbsp;<code 
class="code">ccc&nbsp;8aaa-bbb&nbsp;ddd</code>&nbsp;<code 
class="code">9aaa-bbb&nbsp;rrr_vv</code>&nbsp;&lsquo;<samp class="samp">fff 
[...]
+Out&nbsp;of&nbsp;code&nbsp;&mdash;&nbsp;out-of-code.&nbsp;<code 
class="code">1aaa</code>&nbsp;<code class="code">2aaa-</code>&nbsp;<code 
class="code">-3bbb</code>&nbsp;<code class="code">4aaa-bbb</code>&nbsp;<code 
class="code">&nbsp;5aaa-bb</code>&nbsp;<code 
class="code">6aaa-bb&nbsp;</code>&nbsp;<code 
class="code">ccc&nbsp;7aaa-bbb</code>&nbsp;<code 
class="code">ccc&nbsp;8aaa-bbb&nbsp;ddd</code>&nbsp;<code 
class="code">9aaa-bbb&nbsp;rrr_vv</code>&nbsp;&lsquo;<samp 
class="samp">fff--&nbs [...]
 </p>
 <div class="example">
 <pre class="example-preformatted"><code class="code">in-example</code><!-- /@w 
-->
diff --git a/tp/tests/formatting/res_parser/cpp_lines/cpp_lines.html 
b/tp/tests/formatting/res_parser/cpp_lines/cpp_lines.html
index eed5b2a559..9400a0f1ab 100644
--- a/tp/tests/formatting/res_parser/cpp_lines/cpp_lines.html
+++ b/tp/tests/formatting/res_parser/cpp_lines/cpp_lines.html
@@ -47,7 +47,7 @@
 </p>
 <p><a class="email" href="mailto:after%20inc";>after inc</a>. 
 </p>
-<p><code 
class="verb">&nbsp;#line&nbsp;5&nbsp;&quot;in&nbsp;verb&quot;&nbsp;</code>
+<p><code class="verb"><br>#line&nbsp;5&nbsp;&quot;in&nbsp;verb&quot;<br></code>
 </p>
 <p><a class="email" href="mailto:after%20verb";>after verb</a>
 </p>



reply via email to

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