[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 .= ' ' if (chomp($text));
$text =~ s/ / /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>‘<code class="verb"> </code>’
</p>
-<p>‘ <!-- /@w -->’
+<p>‘ <!-- /@w -->’
</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>
</p>
</div>
-<h4 class="node">c <!-- /@w --></h4>
+<h4 class="node">c <!-- /@w --></h4>
<p><a class="ref" href="#a-">a </a>
</p>
<p><a class="ref" href="#b-">b<code class="verb"> </code></a>
</p>
-<p><a class="ref" href="#c-">c <!-- /@w --></a>
+<p><a class="ref" href="#c-">c <!-- /@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> a rr ggg.<!-- /@w -->
+<p> a rr ggg.<!-- /@w -->
</p>
<p>AA<!-- /@w -->bbb.
</p>
<p>FFd<!-- /@w -->nnn.
</p>
-<p>aa f f<!-- /@w -->ggg.
+<p>aa f f<!-- /@w -->ggg.
</p>
-<p>aa2 f f <!-- /@w -->ggg2.
+<p>aa2 f f <!-- /@w -->ggg2.
</p>
-<p>aa3 f f <!-- /@w -->ggg3.
+<p>aa3 f f <!-- /@w -->ggg3.
</p>
-<p>aa4 f f <!-- /@w --> ggg4.
+<p>aa4 f f <!-- /@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 verb ggg </code></a>.
+<p>See <a class="xref" href="#Top"><code
class="verb">with<br>verb<br><br>ggg </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">• <a href="manual.html#Top"
accesskey="1">(manual)</a>:</td><td> </td><td
class="menu-entry-description">
-<code class="verb"> in verb </code>
+<code class="verb"> in 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>’
</pre></div>
<p>In w:
-Out of code — out-of-code. <code
class="code">1aaa</code> <code class="code">2aaa-</code> <code
class="code">-3bbb</code> <code
class="code">4aaa-bbb</code> <code
class="code"> 5aaa-bb</code> <code
class="code">6aaa-bb </code> <code
class="code">ccc 7aaa-bbb</code> <code
class="code">ccc 8aaa-bbb ddd</code> <code
class="code">9aaa-bbb rrr_vv</code> ‘<samp class="samp">fff
[...]
+Out of code — out-of-code. <code
class="code">1aaa</code> <code class="code">2aaa-</code> <code
class="code">-3bbb</code> <code class="code">4aaa-bbb</code> <code
class="code"> 5aaa-bb</code> <code
class="code">6aaa-bb </code> <code
class="code">ccc 7aaa-bbb</code> <code
class="code">ccc 8aaa-bbb ddd</code> <code
class="code">9aaa-bbb rrr_vv</code> ‘<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"> #line 5 "in verb" </code>
+<p><code class="verb"><br>#line 5 "in verb"<br></code>
</p>
<p><a class="email" href="mailto:after%20verb">after verb</a>
</p>
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- branch master updated: Treat spaces in @verb and @w differently in HTML,
Gavin D. Smith <=