bug-texinfo
[Top][All Lists]
Advanced

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

Re: use id="xx" instead of <a name="xx"> in html output


From: Gavin Smith
Subject: Re: use id="xx" instead of <a name="xx"> in html output
Date: Sun, 14 Feb 2016 13:37:02 +0000

On 9 February 2016 at 20:07, Per Bothner <address@hidden> wrote:

> Using "id" makes sense when it is the name of a sub-tree, like a chapter
> or section, since it can be directly associated with an element that
> represents the subtree.
>
> Using <a name="xx"> is reasonable when it is the name of a *position*,
> as resulting from an @anchor.  Though being able to use getElementById
> is an argument for using id for positions as well.  I.e. you can do:
>
> <span class="anchor" id="foo></span>
>
> as equivalent to:
>
> <a name="foo"/>
>
> The main reason to prefer the former is using getElementById.
> But I think that is good reason.

I think I've worked out how to wrap each section, not including any
subsections, in an element:

Index: Texinfo/Convert/HTML.pm
===================================================================
--- Texinfo/Convert/HTML.pm     (revision 7015)
+++ Texinfo/Convert/HTML.pm     (working copy)
@@ -4394,6 +4394,22 @@ sub _convert_element_type($$$$)
   my $result = '';
   my $special_element;

+  my $id = '';
+  if ($element->{'extra'}->{'node'}) {
+    $id = $self->command_id($element->{'extra'}->{'node'});
+    if ($id) {
+      $id = " id=\"$id\"";
+    }
+  }
+  my $section = '';
+  if ($element->{'extra'}->{'section'}) {
+    $section = $element->{'extra'}->{'section'}->{'cmdname'};
+    if ($section) {
+      $section = " class=\"$section\"";
+    }
+  }
+  $result .= "<div$section$id>\n";
+
   if ($element->{'extra'}->{'special_element'}) {
     $special_element = $element->{'extra'}->{'special_element'};
     my $id = $self->command_id($element);
@@ -4437,6 +4453,7 @@ sub _convert_element_type($$$$)
   $result .= $content unless ($special_element);
   $result .= &{$self->{'format_element_footer'}}($self, $type,
                                                  $element, $content);
+  $result .= "</div>\n";
   return $result;
 }



I'm going to look at how the nesting is done in the code for XML
output so that a <div> for a @section can be put inside the <div> for
the containing @chapter, instead of being put at the same level as is
done here.

The code that outputs the <a name> tag is elsewhere (in
_convert_heading_command): that would have to be changed as well:
possibly by moving all the code into _convert_element_type.



reply via email to

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