[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
texinfo/tp README Texinfo/Structuring.pm Texinf...
From: |
Patrice Dumas |
Subject: |
texinfo/tp README Texinfo/Structuring.pm Texinf... |
Date: |
Sat, 16 Apr 2011 16:36:39 +0000 |
CVSROOT: /sources/texinfo
Module name: texinfo
Changes by: Patrice Dumas <pertusus> 11/04/16 16:36:38
Modified files:
tp : README
tp/Texinfo : Structuring.pm
tp/Texinfo/Convert: Converter.pm HTML.pm Plaintext.pm
Log message:
New function to sort index entries by letter.
Prepare indices (sorting and do id and targets) in HTML.
Begin formatting of definitions.
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/README?cvsroot=texinfo&r1=1.1&r2=1.2
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/Texinfo/Structuring.pm?cvsroot=texinfo&r1=1.53&r2=1.54
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/Texinfo/Convert/Converter.pm?cvsroot=texinfo&r1=1.14&r2=1.15
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/Texinfo/Convert/HTML.pm?cvsroot=texinfo&r1=1.23&r2=1.24
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/Texinfo/Convert/Plaintext.pm?cvsroot=texinfo&r1=1.135&r2=1.136
Patches:
Index: README
===================================================================
RCS file: /sources/texinfo/texinfo/tp/README,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- README 20 Sep 2010 17:19:04 -0000 1.1
+++ README 16 Apr 2011 16:36:38 -0000 1.2
@@ -19,6 +19,9 @@
blah blah blah
+On ubuntu/debian
+libdata-compare-perl libtest-deep-perl libclone-perl
+
COPYRIGHT AND LICENCE
Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009,
Index: Texinfo/Structuring.pm
===================================================================
RCS file: /sources/texinfo/texinfo/tp/Texinfo/Structuring.pm,v
retrieving revision 1.53
retrieving revision 1.54
diff -u -b -r1.53 -r1.54
--- Texinfo/Structuring.pm 12 Apr 2011 23:52:53 -0000 1.53
+++ Texinfo/Structuring.pm 16 Apr 2011 16:36:38 -0000 1.54
@@ -47,6 +47,7 @@
number_floats
merge_indices
sort_indices
+ sort_indices_by_letter
) ] );
@EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
@@ -813,7 +814,7 @@
my $command = $element->{'extra'}->{'element_command'};
if (!defined($command)) {
- #Â happens when there are only nodes and sections are used as elements
+ # happens when there are only nodes and sections are used as elements
my $result = "No associated command ";
$result .= "(type $element->{'type'})" if (defined($element->{'type'}));
return $result;
@@ -910,16 +911,36 @@
}
}
+sub _sort_string($$)
+{
+ my $a = shift;
+ my $b = shift;
+ return (($a =~ /^[[:alpha:]]/ and $b =~ /^[[:alpha:]]/)
+ or ($a !~ /^[[:alpha:]]/ and $b !~ /^[[:alpha:]]/))
+ ? ($a cmp $b)
+ : (($a =~ /^[[:alpha:]]/ && 1) || -1);
+}
+
sub _sort_subroutine($$)
{
my $key1 = shift;
my $key2 = shift;
my $a = uc($key1->{'key'});
my $b = uc($key2->{'key'});
- my $res = (($a =~ /^[[:alpha:]]/ and $b =~ /^[[:alpha:]]/)
- or ($a !~ /^[[:alpha:]]/ and $b !~ /^[[:alpha:]]/))
- ? ($a cmp $b)
- : (($a =~ /^[[:alpha:]]/ && 1) || -1);
+ my $res = _sort_string($a, $b);
+ if ($res == 0) {
+ $res = ($key1->{'number'} <=> $key2->{'number'});
+ }
+ return $res;
+}
+
+sub _sort_entries_in_letter($$)
+{
+ my $key1 = shift;
+ my $key2 = shift;
+ my $a = uc($key1->{'key'});
+ my $b = uc($key2->{'key'});
+ my $res = ($a cmp $b);
if ($res == 0) {
$res = ($key1->{'number'} <=> $key2->{'number'});
}
@@ -943,7 +964,7 @@
}
}
-sub sort_indices ($$)
+sub sort_indices($$)
{
my $self = shift;
my $index_entries = shift;
@@ -956,6 +977,28 @@
return $sorted_index_entries;
}
+sub sort_indices_by_letter($$)
+{
+ my $self = shift;
+ my $index_entries = shift;
+ my $indices_sorted_by_letters;
+ _do_index_keys($self, $index_entries);
+ foreach my $index_name (keys(%$index_entries)) {
+ my $index_letter_hash;
+ foreach my $index_entry (@{$index_entries->{$index_name}}) {
+ my $letter = uc(substr($index_entry->{'key'}, 0, 1));
+ push @{$index_letter_hash->{$letter}}, $index_entry;
+ }
+ foreach my $letter (sort _sort_string (keys %$index_letter_hash)) {
+ my @sorted_letter_entries
+ = sort _sort_entries_in_letter @{$index_letter_hash->{$letter}};
+ push @{$indices_sorted_by_letters->{$index_name}},
+ { 'letter' => $letter, 'entries' => address@hidden };
+ }
+ }
+ return $indices_sorted_by_letters;
+}
+
sub merge_indices($$$)
{
my $index_names = shift;
Index: Texinfo/Convert/Converter.pm
===================================================================
RCS file: /sources/texinfo/texinfo/tp/Texinfo/Convert/Converter.pm,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -b -r1.14 -r1.15
--- Texinfo/Convert/Converter.pm 15 Apr 2011 06:39:33 -0000 1.14
+++ Texinfo/Convert/Converter.pm 16 Apr 2011 16:36:38 -0000 1.15
@@ -420,6 +420,53 @@
'day' => $mday, 'year' => $year });
}
+sub definition_category($$$$)
+{
+ my $self = shift;
+ my $current = shift;
+ my $arg_category = shift;
+ my $arg_class = shift;
+ return $arg_category
+ if (!defined($arg_class));
+
+ my $style =
+
$Texinfo::Common::command_index_prefix{$current->{'extra'}->{'def_command'}};
+ #my $category = Texinfo::Convert::Texinfo::convert($arg_category->[0]);
+ #my $class = Texinfo::Convert::Texinfo::convert($arg_class->[0]);
+ #print STDERR "DEFINITION CATEGORY($style): $category $class\n"
+ # if ($self->get_conf('DEBUG'));
+ if ($style eq 'f') {
+ #return Texinfo::Parser::parse_texi_line (undef, "$category on $class");
+ return $self->gdt('{category} on {class}', { 'category' => $arg_category,
+ 'class' => $arg_class });
+ } elsif ($style eq 'v') {
+ #return Texinfo::Parser::parse_texi_line (undef, "$category of $class");
+ return $self->gdt('{category} of {class}', { 'category' => $arg_category,
+ 'class' => $arg_class });
+ }
+ return $arg_category;
+}
+
+sub definition_arguments_content($$)
+{
+ my $self = shift;
+ my $root = shift;
+ my $result;
+
+ my @args = @{$root->{'extra'}->{'def_args'}};
+ while (@args) {
+ last if ($args[0]->[0] ne 'spaces'
+ and !$root->{'extra'}->{'def_parsed_hash'}->{$args[0]->[0]});
+ shift @args;
+ }
+ if (@args) {
+ foreach my $arg (@args) {
+ push @$result, $arg->[1];
+ }
+ }
+ return $result;
+}
+
sub xml_protect_text($$)
{
my $self = shift;
Index: Texinfo/Convert/HTML.pm
===================================================================
RCS file: /sources/texinfo/texinfo/tp/Texinfo/Convert/HTML.pm,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -b -r1.23 -r1.24
--- Texinfo/Convert/HTML.pm 15 Apr 2011 06:39:33 -0000 1.23
+++ Texinfo/Convert/HTML.pm 16 Apr 2011 16:36:38 -0000 1.24
@@ -736,8 +736,12 @@
if ($cmdname eq $self->{'output_format'}) {
chomp ($contents);
return $contents;
+ # FIXME compatibility with texi2html
+ } elsif ($cmdname eq 'tex') {
+ return $self->attribute_class('pre', $cmdname).'>'
+ .$self->xml_protect_text($contents) . '</pre>';
}
- $self->line_warn(sprintf(__("Raw format %s is not converted"), $cmdname),
+ $self->line_warn(sprintf($self->__("Raw format %s is not converted"),
$cmdname),
$command->{'line_nr'});
return $self->xml_protect_text($contents);
}
@@ -876,6 +880,63 @@
$default_types_conversion{'text'} = \&_convert_text;
+sub _convert_def_line_type($$$$)
+{
+ my $self = shift;
+ my $type = shift;
+ my $command = shift;
+ # FIXME content?
+ my $content = shift;
+
+ if ($command->{'extra'} and $command->{'extra'}->{'def_args'}
+ and @{$command->{'extra'}->{'def_args'}}) {
+ my $parsed_definition_category = $self->definition_category ($command,
+ $command->{'extra'}->{'def_parsed_hash'}->{'category'},
+ $command->{'extra'}->{'def_parsed_hash'}->{'class'});
+ }
+ my $arguments_content = $self->definition_arguments_content($command);
+ my $arguments = '';
+ if ($arguments_content) {
+ $arguments = $self->convert_text({'type' => '_code',
+ 'contents' => $arguments_content});
+ $arguments = '<em>' . $arguments . '</em>' if ($arguments =~ /\S/);
+ }
+ my $index_label = '';
+ my $index_id = $self->command_id ($command);
+ if (defined($index_id)) {
+ $index_label = "<a href=\"$index_id\"></a>";
+ }
+ my $category_prepared = '';
+ my $type_name = '';
+ if (!$self->get_conf('DEF_TABLE')) {
+ return '<dt>'.$index_label.$category_prepared . ':' . $type_name .
"</dt>\n";
+ } else {
+ return "<tr><td align=\"left\">" . $type_name .
+ "</td><td align=\"right\">" . $category_prepared .
+ $index_label . "</td></tr>\n";
+ }
+}
+
+$default_types_conversion{'def_line'} = \&_convert_def_line_type;
+
+sub _convert_def_command($$$$) {
+ my $self = shift;
+ my $cmdname = shift;
+ my $command = shift;
+ my $args = shift;
+ my $contents = shift;
+
+ if (!$self->get_conf('DEF_TABLE')) {
+ return "<dl>\n". $contents ."</dl>\n";
+ } else {
+ return "<table width=\"100%\">\n" . $contents . "</table>\n";
+ }
+}
+
+foreach my $command (keys(%def_commands)) {
+ $default_commands_conversion{$command} = \&_convert_def_command;
+}
+
sub _convert_element_type($$$$)
{
my $self = shift;
@@ -886,7 +947,7 @@
#print STDERR "GGGGGGGG $command->{'parent'}
$command->{'parent'}->{'type'}\n";
my $result = '';
$result .= $content;
- #Â FIXME titlepage
+ # FIXME titlepage
if (!$command->{'element_prev'}) {
if (!$command->{'element_next'}) {
return $result.$self->get_conf('DEFAULT_RULE')."\n";
@@ -905,7 +966,7 @@
my $result = '';
- #Â This may happen if there are only nodes and sections are used as elements
+ # This may happen if there are only nodes and sections are used as elements
#die "BUG: no 'element_command' for $element"
# if (!$element->{'extra'}->{'element_command'});
die "BUG: no target for $element"
@@ -1260,6 +1321,7 @@
$self->{'targets'}->{$root_command} = {'target' => $target,
'id' => $id,
'node_filename' => $filename};
+ $self->{'ids'}->{$id} = $root_command;
}
}
@@ -1267,7 +1329,7 @@
foreach my $element (@$elements) {
foreach my $root_command(@{$element->{'contents'}}) {
# FIXME this happens for type 'text_root' which precedes the
- #Â root commands. The target may also already be set for top node.
+ # root commands. The target may also already be set for top node.
next if (!defined($root_command->{'cmdname'})
or $self->{'targets'}->{$root_command});
if ($Texinfo::Common::root_commands{$root_command->{'cmdname'}}) {
@@ -1277,7 +1339,7 @@
$no_unidecode));
my $nr=0;
my $target = $target_base;
- while ($self->{'labels'}->{$target}) {
+ while ($self->{'ids'}->{$target}) {
$target = $target_base.'-'.$nr;
$nr++;
# Avoid integer overflow
@@ -1299,6 +1361,7 @@
}
$self->{'targets'}->{$root_command} = {'target' => $target,
'id' => $id};
+ $self->{'ids'}->{$id} = $root_command;
}
}
}
@@ -1564,14 +1627,61 @@
$self->_set_page_file($page, $filename);
push @$pages, $page;
}
+ # FIXME add element, page... (see command_filename)?
$self->{'targets'}->{$element} = {'id' => $id,
'target' => $target,
'filename' => $filename,
};
+ $self->{'ids'}->{$id} = $element;
}
return ($elements, $pages);
}
+sub _prepare_index_entries($)
+{
+ my $self = shift;
+
+
+ if ($self->{'parser'}) {
+ my $no_unidecode;
+ $no_unidecode = 1 if (defined($self->get_conf('USE_UNIDECODE'))
+ and !$self->get_conf('USE_UNIDECODE'));
+
+ my ($index_names, $merged_indices, $index_entries)
+ = $self->{'parser'}->indices_information();
+ $self->{'index_entries_by_letter'}
+ = $self->Texinfo::Structuring::sort_indices_by_letter(
+ Texinfo::Structuring::merge_indices($index_names, $merged_indices,
+ $index_entries));
+
+ foreach my $index_entry (@$index_entries) {
+ my ($page, $element, $root_command)
+ = $self->_get_page($index_entry->{'command'});
+ my $region = '';
+ $region = "$index_entry->{'region'}-"
+ if (defined($index_entry->{'region'}) and $index_entry->{'region'} ne
'');
+ my $normalized_index = _normalized_to_id(
+ Texinfo::Convert::NodeNameNormalization::transliterate_texinfo(
+ {'contents' => $index_entry->{'content'}},
+ $no_unidecode));
+ my $target_base = "index-" . $region .$normalized_index;
+ my $nr=1;
+ my $target = $target_base;
+ while ($self->{'ids'}->{$target}) {
+ $target = $target_base.'-'.$nr;
+ $nr++;
+ # Avoid integer overflow
+ die if ($nr == 0);
+ }
+ my $id = $target;
+ $self->{'ids'}->{$target} = $index_entry->{'command'};
+ $self->{'targets'}->{$index_entry->{'command'}} = { 'id' => $id,
+ 'target' => $target,
+ };
+ }
+ }
+}
+
sub htmlxref($$)
{
my $self = shift;
@@ -1939,6 +2049,7 @@
# This should return undef if called on a tree without node or sections.
my $elements = $self->_prepare_elements($root);
+ $self->_prepare_index_entries();
if (!defined($elements)) {
$result = $self->_convert($root);
@@ -1995,6 +2106,10 @@
# 'destination_directory' and 'output_filename' that are useful when split.
$self->_set_outfile();
+ # Do that before the other elements, to be sure that special page ids
+ # are registered before elements id are.
+ my ($special_elements, $special_pages) = $self->_prepare_special_elements();
+
# This should return undef if called on a tree without node or sections.
my $elements = $self->_prepare_elements($root);
@@ -2007,17 +2122,15 @@
$self->{'pages'} = $pages;
- my ($special_elements, $special_pages) = $self->_prepare_special_elements();
-
# determine file names associated with the different pages, and setup
- #Â the counters for special element pages.
+ # the counters for special element pages.
$self->_set_page_files($pages, $special_pages);
# do element directions. FIXME do it here or before? Here it means that
# PrevFile and NextFile can be set.
Texinfo::Structuring::element_directions($self, $elements);
- #Â associate the special elements that have no page to the main page.
+ # associate the special elements that have no page to the main page.
# This may only happen if not split.
if ($special_elements) {
foreach my $special_element (@$special_elements) {
@@ -2034,6 +2147,11 @@
# FIXME Before that, set multiple commands
# FIXME set language and documentencoding/encoding_name
+ # FIXME determine index entries id/targets and set them as 'ids' and
+ # 'targets'. texi2html.pl l. 7807
+ $self->_prepare_index_entries();
+
+
# TODO Top, Index, First, Last.
$self->set_conf('BODYTEXT', 'lang="' . $self->get_conf('documentlanguage')
Index: Texinfo/Convert/Plaintext.pm
===================================================================
RCS file: /sources/texinfo/texinfo/tp/Texinfo/Convert/Plaintext.pm,v
retrieving revision 1.135
retrieving revision 1.136
diff -u -b -r1.135 -r1.136
--- Texinfo/Convert/Plaintext.pm 15 Apr 2011 06:39:33 -0000 1.135
+++ Texinfo/Convert/Plaintext.pm 16 Apr 2011 16:36:38 -0000 1.136
@@ -573,33 +573,6 @@
return $result;
}
-sub _definition_category($$$$)
-{
- my $self = shift;
- my $current = shift;
- my $arg_category = shift;
- my $arg_class = shift;
- return $arg_category
- if (!defined($arg_class));
-
- my $style =
-
$Texinfo::Common::command_index_prefix{$current->{'extra'}->{'def_command'}};
- #my $category = Texinfo::Convert::Texinfo::convert($arg_category->[0]);
- #my $class = Texinfo::Convert::Texinfo::convert($arg_class->[0]);
- #print STDERR "DEFINITION CATEGORY($style): $category $class\n"
- # if ($self->get_conf('DEBUG'));
- if ($style eq 'f') {
- #return Texinfo::Parser::parse_texi_line (undef, "$category on $class");
- return $self->gdt('{category} on {class}', { 'category' => $arg_category,
- 'class' => $arg_class });
- } elsif ($style eq 'v') {
- #return Texinfo::Parser::parse_texi_line (undef, "$category of $class");
- return $self->gdt('{category} of {class}', { 'category' => $arg_category,
- 'class' => $arg_class });
- }
- return $arg_category;
-}
-
sub count_bytes($$)
{
my $self = shift;
@@ -2082,7 +2055,7 @@
} elsif ($root->{'type'} eq 'def_line') {
if ($root->{'extra'} and $root->{'extra'}->{'def_args'}
and @{$root->{'extra'}->{'def_args'}}) {
- my $parsed_definition_category = $self->_definition_category ($root,
+ my $parsed_definition_category = $self->definition_category ($root,
$root->{'extra'}->{'def_parsed_hash'}->{'category'},
$root->{'extra'}->{'def_parsed_hash'}->{'class'});
# FIXME need i18n here?
@@ -2093,18 +2066,10 @@
}
push @contents, $root->{'extra'}->{'def_parsed_hash'}->{'name'};
- my @args = @{$root->{'extra'}->{'def_args'}};
- while (@args) {
- last if ($args[0]->[0] ne 'spaces'
- and !$root->{'extra'}->{'def_parsed_hash'}->{$args[0]->[0]});
- shift @args;
- }
-
- if (@args) {
+ my $arguments = $self->definition_arguments_content($root);
+ if ($arguments) {
push @contents, {'text' => ' '};
- foreach my $arg (@args) {
- push @contents, $arg->[1];
- }
+ push @contents, @$arguments;
}
my $def_paragraph = $self->new_formatter('paragraph',
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- texinfo/tp README Texinfo/Structuring.pm Texinf...,
Patrice Dumas <=