bug-texinfo
[Top][All Lists]
Advanced

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

Re: html structure revisited


From: Gavin Smith
Subject: Re: html structure revisited
Date: Sat, 20 Feb 2021 20:34:06 +0000

On Tue, Feb 16, 2021 at 12:40 AM Per Bothner <per@bothner.com> wrote:
>
> A possible minor optional refinement.  Instead of:
>
>      <span id="Wire-byte-protocol-1"></span>
>      <h3 class="section">Wire byte protocol</h3>
>
> the following is marginally nicer:
>
>      <h3 id="Wire-byte-protocol-1" class="section">Wire byte protocol</h3>
>
> Totally not important.
> (Certainly not enough for me to try to figure out how to do it ...)

Ideally there would be no id output at all but I don't want to figure
it out just now, in case there is a link to that anchor from
somewhere. I tried the change at the bottom of this email which
produces good results in most, but not all cases. It is aggravating
when you see that output and you think it would be much better with
the other output, but it is risky, I think, to take out an id in one
place and put it in in another place. The risk is that either we get
two identical ids (which is wrong), or a link to a missing id (also
wrong). I would like to leave this issue just now as the output is not
actually broken.

diff --git a/tp/Texinfo/Convert/HTML.pm b/tp/Texinfo/Convert/HTML.pm
index aa15ba0663..eb12a99696 100644
--- a/tp/Texinfo/Convert/HTML.pm
+++ b/tp/Texinfo/Convert/HTML.pm
@@ -1990,6 +1990,12 @@ sub _default_format_heading_text($$$$$)
     $class = $cmdname;
   }

+  my $element_id = $self->command_id($command);
+  my $id = '';
+  if ($element_id) {
+    $id = " id=\"$element_id\"";
+  }
+
   my $align = '';
   $align = ' align="center"' if ($cmdname eq 'centerchap' or $cmdname
eq 'settitle');
   if ($level < 1) {
@@ -1997,7 +2003,7 @@ sub _default_format_heading_text($$$$$)
   } elsif ($level > $self->get_conf('MAX_HEADER_LEVEL')) {
     $level = $self->get_conf('MAX_HEADER_LEVEL');
   }
-  my $result = $self->_attribute_class("h$level", $class)
."$align>$text</h$level>";
+  my $result = $self->_attribute_class("h$level", $class)
."$id$align>$text</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 ($cmdname eq 'titlefont');
@@ -2458,7 +2464,6 @@ sub _convert_heading_command($$$$$)
     return $result;
   }

-  my $element_id = $self->command_id($command);
   my $section;
   if ($cmdname eq 'node' and $command->{'extra'}->{'associated_section'}) {
     $section = $command->{'extra'}->{'associated_section'};
@@ -2475,13 +2480,11 @@ sub _convert_heading_command($$$$$)
     $self->register_opened_section_level($level, "</div>\n");

     $result .= '<div class="' . $section->{'cmdname'} . '"';
-
-    $result .= " id=\"$element_id\""
-        if (defined($element_id) and $element_id ne '');
+    my $element_id = $self->command_id($command);
+    if ($element_id and $cmdname eq 'node') {
+      $result .= " id=\"$element_id\"";
+    }
     $result .= ">\n";
-  } else {
-    $result .= "<span id=\"$element_id\"></span>"
-        if (defined($element_id) and $element_id ne '');
   }

   print STDERR "Process $command "



reply via email to

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