On Mon, Dec 31, 2018 at 01:14:28PM -0800, Per Bothner wrote: > See this old thread: > https://lists.gnu.org/archive/html/bug-texinfo/2016-02/msg00056.html > > Attached is a simple patch to generate better-structured html. > > It wraps all nodes (anything processed by _convert_heading_command) in a > <div> block. > It uses id="xx" instead of <a name="xx">. When I could, I attached the id to > existing > elements (or the new <div> block); otherwise I replaced the <a> by a <span>.
Thanks for working on this. What else needs to be changed so that the output is valid for HTML 5? I assume that the DOCTYPE declaration would need to be changed - currently it is <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> I worked on your patch to make the new output enabled by passing "-c HTML_VERSION=HTML5" to texi2any. Do you think the patch below will be acceptable? I will look over it tomorrow again before I commit it. PS Texinfo is using git now for its development. diff --git a/ChangeLog b/ChangeLog index e1f366c..9ca62d3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,21 @@ +2019-01-01 Per Bother <[email protected]>, and + Gavin Smith <[email protected]> + + * tp/Texinfo/Common.pm (@variable_string_settables), + * tp/Texinfo/Convert/HTML.pm (%defaults): + Add HTML_VERSION. + * tp/Texinfo/Convert/HTML.pm (_href_target): New subroutine, + using '<span id>' instead of '<a name>' if HTML_VERSION is set + to "HTML5". + (_convert_float_command, _convert_item_command) + (_convert_index_command, _contents_inline_element) + (_convert_element_type): Call it. + (_convert_heading_command) [HTML5]: Wrap nodes in a <div> block. + (_convert_printindex_command) [HTML5], + (_convert_def_line_type) [HTML5]: + Add 'id' attribute to <th> element and remove <a name>. + + 2019-01-01 Gavin Smith <[email protected]> Document SECTION_NAME_IN_TITLE. diff --git a/tp/Texinfo/Common.pm b/tp/Texinfo/Common.pm index 336345d..4aca57b 100644 --- a/tp/Texinfo/Common.pm +++ b/tp/Texinfo/Common.pm @@ -213,7 +213,7 @@ my @formats_settable = ( my @variable_string_settables = ( 'DEBUG', 'FRAMES', 'FRAMESET_DOCTYPE', 'DOCTYPE', 'TEST', 'DUMP_TEXI', 'TOP_FILE', 'SHOW_MENU', 'USE_NODES', 'TOC_LINKS', 'SHORTEXTN', - 'PREFIX', 'DEF_TABLE', 'L2H', 'MONOLITHIC', + 'HTML_VERSION', 'PREFIX', 'DEF_TABLE', 'L2H', 'MONOLITHIC', 'L2H_L2H', 'L2H_SKIP', 'L2H_TMP', 'L2H_FILE', 'L2H_CLEAN', 'L2H_HTML_VERSION', 'EXTERNAL_DIR', 'USE_ISO', 'VERTICAL_HEAD_NAVIGATION', 'INLINE_CONTENTS', 'NODE_FILE_EXTENSION', diff --git a/tp/Texinfo/Convert/HTML.pm b/tp/Texinfo/Convert/HTML.pm index 10d3073..9de4ab2 100644 --- a/tp/Texinfo/Convert/HTML.pm +++ b/tp/Texinfo/Convert/HTML.pm @@ -922,6 +922,7 @@ my %PASSIVE_ICONS = ( my %defaults = ( + 'HTML_VERSION' => 'HTML_4.01_TRANSITIONAL', 'ENABLE_ENCODING' => 0, 'SHOW_MENU' => 1, 'OUTPUT_ENCODING_NAME' => 'utf-8', @@ -1554,6 +1555,16 @@ foreach my $explained_command (keys(%explained_commands)) { = \&_convert_explained_command; } +sub _href_target { + my ($self, $id) = @_; + + if ($self->get_conf('HTML_VERSION') ne 'HTML5') { + return "<a name=\"$id\"></a>"; + } else { + return "<span id=\"$id\"></span>"; + } +} + sub _convert_anchor_command($$$$) { my $self = shift; @@ -1564,7 +1575,7 @@ sub _convert_anchor_command($$$$) my $id = $self->command_id($command); if (defined($id) and $id ne '' and !@{$self->{'multiple_pass'}} and !$self->in_string()) { - return "<a name=\"$id\"></a>"; + return _href_target($self, $id); } return ''; } @@ -2309,8 +2320,14 @@ sub _convert_heading_command($$$$$) } my $element_id = $self->command_id($command); - $result .= "<a name=\"$element_id\"></a>\n" - if (defined($element_id) and $element_id ne ''); + if ($self->get_conf('HTML_VERSION') ne 'HTML5') { + $result .= "<a name=\"$element_id\">\n"; + } else { + $result .= "<div cmdname=\"$cmdname\""; + $result .= " id=\"$element_id\"" + if (defined($element_id) and $element_id ne ''); + $result .= ">\n"; + } print STDERR "Process $command " .Texinfo::Structuring::_print_root_command_texi($command)."\n" @@ -2393,6 +2410,9 @@ sub _convert_heading_command($$$$$) } } } + if ($self->get_conf('HTML_VERSION') eq 'HTML5') { + $result .= "</div>\n"; + } return $result; } @@ -2820,7 +2840,7 @@ sub _convert_float_command($$$$$) my $id = $self->command_id($command); my $label; if (defined($id) and $id ne '') { - $label = "<a name=\"$id\"></a>"; + $label = _href_target($self, $id); } else { $label = ''; } @@ -3071,7 +3091,7 @@ sub _convert_item_command($$$$) } my $index_id = $self->command_id ($command); if (defined($index_id) and $index_id ne '') { - $result .= "\n<a name=\"$index_id\"></a>\n"; + $result .= "\n" . _href_target($self, $index_id) . "\n"; } return '<dt>' .$result. '</dt>' . "\n"; @@ -3378,7 +3398,7 @@ sub _convert_index_command($$$$) if (defined($index_id) and $index_id ne '' and !@{$self->{'multiple_pass'}} and !$self->in_string()) { - my $result = "<a name=\"$index_id\"></a>"; + my $result = _href_target($self, $index_id); $result .= "\n" unless ($self->in_preformatted()); return $result; } @@ -3536,9 +3556,14 @@ sub _convert_printindex_command($$$$) if ($associated_command_href); $entries_text .= "</td></tr>\n"; } - # a letter and associated indice entries - $result .= '<tr><th>' . - "<a name=\"$letter_id{$letter}\">".$self->protect_text($letter).'</a>' + # a letter and associated index entries + $result .= '<tr>'; + if ($self->get_conf('HTML_VERSION') eq 'HTML5') { + $result .= "<th id=\"$letter_id{$letter}\">"; + } else { + $result .= "<th><a name=\"$letter_id{$letter}\">"; + } + $result .= $self->protect_text($letter) . "</th><td></td><td></td></tr>\n" . $entries_text . "<tr><td colspan=\"4\"> ".$self->get_conf('DEFAULT_RULE')."</td></tr>\n"; @@ -3567,7 +3592,7 @@ sub _contents_inline_element($$$) if ($special_element) { my $id = $self->command_id($special_element); if ($id ne '') { - $result .= "<a name=\"$id\"></a>\n"; + $result .= _href_target($self, $id) . "\n"; } $heading = $self->command_text($special_element); } else { @@ -4052,11 +4077,11 @@ sub _convert_def_line_type($$$$) $command, Texinfo::Common::_convert_text_options($self))); } - my $index_label = ''; - my $index_id = $self->command_id($command); - if (defined($index_id) and $index_id ne '' and !@{$self->{'multiple_pass'}}) { - $index_label = "<a name=\"$index_id\"></a>"; + my $index_id; + if (!@{$self->{'multiple_pass'}}) { + $index_id = $self->command_id($command); } + my $arguments = Texinfo::Common::definition_arguments_content($command); @@ -4234,8 +4259,17 @@ sub _convert_def_line_type($$$$) } } - return '<dt>'.$index_label.$self->convert_tree({'type' => '_code', + my $result; + if (!$index_id) { + $result = '<dt>'; + } elsif ($self->get_conf('HTML_VERSION') ne 'HTML5') { + $result = "<dt><a name=\"$index_id\"></a>"; + } else { + $result = "<dt id=\"$index_id\">"; + } + $result .= $self->convert_tree({'type' => '_code', 'contents' => [$tree]}) . "</dt>\n"; + return $result; } else { my $category_prepared = ''; if ($command->{'extra'} and $command->{'extra'}->{'def_parsed_hash'} @@ -4272,9 +4306,22 @@ sub _convert_def_line_type($$$$) $type_name .= ' <strong>' . $name . '</strong>' if ($name ne ''); $type_name .= $arguments_text; - return "<tr><td align=\"left\">" . $type_name . - "</td><td align=\"right\">" . $category_prepared . - $index_label . "</td></tr>\n"; + my $index_label; + if ($self->get_conf('HTML_VERSION') ne 'HTML5') { + if ($index_id) { + $index_label = "<a name=\"$index_id\"></a>"; + } + return "<tr><td align=\"left\">" . $type_name . + "</td><td align=\"right\">" . $category_prepared . + $index_label . "</td></tr>\n"; + + } else { + if ($index_id) { + $index_label = " id=\"$index_id\""; + } + return "<tr$index_label><td align=\"left\">" . $type_name . + "</td><td align=\"right\">" . $category_prepared . "</td></tr>\n"; + } } } @@ -4431,7 +4478,7 @@ sub _convert_element_type($$$$) $special_element = $element->{'extra'}->{'special_element'}; my $id = $self->command_id($element); if ($id ne '') { - $result .= "<a name=\"$id\"></a>\n"; + $result .= _href_target($self, $id); } if ($self->get_conf('HEADERS') # first in page
