[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
texinfo/tp/Texinfo Common.pm Structuring.pm Con...
From: |
Patrice Dumas |
Subject: |
texinfo/tp/Texinfo Common.pm Structuring.pm Con... |
Date: |
Thu, 07 Apr 2011 23:08:05 +0000 |
CVSROOT: /sources/texinfo
Module name: texinfo
Changes by: Patrice Dumas <pertusus> 11/04/07 23:08:05
Modified files:
tp/Texinfo : Common.pm Structuring.pm
tp/Texinfo/Convert: HTML.pm
Log message:
Add informations for element directions and headers.
Setup element directions (sill not working).
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/Texinfo/Common.pm?cvsroot=texinfo&r1=1.30&r2=1.31
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/Texinfo/Structuring.pm?cvsroot=texinfo&r1=1.48&r2=1.49
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/Texinfo/Convert/HTML.pm?cvsroot=texinfo&r1=1.10&r2=1.11
Patches:
Index: Common.pm
===================================================================
RCS file: /sources/texinfo/texinfo/tp/Texinfo/Common.pm,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -b -r1.30 -r1.31
--- Common.pm 6 Apr 2011 23:48:52 -0000 1.30
+++ Common.pm 7 Apr 2011 23:08:04 -0000 1.31
@@ -125,7 +125,9 @@
'PROGRAM_NAME_IN_FOOTER', 'NODE_FILENAMES', 'DEFAULT_ENCODING',
'OUT_ENCODING', 'ENCODING_NAME', 'EXTERNAL_CROSSREF_SPLIT', 'BODYTEXT',
'CSS_LINES', 'RENAMED_NODES_REDIRECTIONS', 'RENAMED_NODES_FILE',
- 'TEXI2DVI', 'DUMP_TREE', 'MAX_MACRO_CALL_NESTING');
+ 'TEXI2DVI', 'DUMP_TREE', 'MAX_MACRO_CALL_NESTING',
+ 'PROGRAM_AND_VERSION', 'PROGRAM_HOMEPAGE', 'PROGRAM',
+ 'AFTER_BODY_OPEN', 'EXTRA_HEAD', 'LINKS_BUTTONS');
my %valid_options;
foreach my $var (@document_settable_at_commands, @document_global_at_commands,
Index: Structuring.pm
===================================================================
RCS file: /sources/texinfo/texinfo/tp/Texinfo/Structuring.pm,v
retrieving revision 1.48
retrieving revision 1.49
diff -u -b -r1.48 -r1.49
--- Structuring.pm 6 Apr 2011 23:48:52 -0000 1.48
+++ Structuring.pm 7 Apr 2011 23:08:04 -0000 1.49
@@ -264,6 +264,7 @@
}
}
if ($new_upper_element) {
+ # In that case the root has to be updated because the first 'part'
just appeared
$content->{'section_up'} = $sec_root;
$sec_root->{'level'} = $level - 1;
push @{$sec_root->{'section_childs'}}, $content;
@@ -552,6 +553,7 @@
$elements->[-1]->{'element_next'} = $current;
push @$elements, $current;
}
+ $elements->[-1]->{'extra'}->{'element_command'} = $content;
}
push @{$current->{'contents'}}, $content;
$content->{'parent'} = $current;
@@ -585,13 +587,18 @@
$elements->[-1]->{'element_next'} = $current;
push @$elements, $current;
}
+ $elements->[-1]->{'extra'}->{'element_command'}
+ = $content->{'extra'}->{'associated_section'};
+ # FIXME Handle part differently? (associate with prev sectioning command?)
} elsif ($content->{'cmdname'} and $content->{'cmdname'} ne 'node'
and $content->{'cmdname'} ne 'bye') {
if ($current->{'extra'}->{'no_section'}) {
delete $current->{'extra'}->{'no_section'};
$current->{'extra'}->{'section'} = $content;
+ $current->{'extra'}->{'element_command'} = $content;
} elsif ($current->{'extra'}->{'section'} ne $content) {
- $current = { 'type' => 'element', 'extra' => {'section' => $content}};
+ $current = { 'type' => 'element', 'extra' => {'section' => $content,
+ 'element_command' => $content}};
$current->{'element_prev'} = $elements->[-1];
$elements->[-1]->{'element_next'} = $current;
push @$elements, $current;
@@ -630,7 +637,12 @@
}
if ($split eq 'node' or (defined($level) and $split_level <= $level)
or address@hidden) {
- push @pages, {'type' => 'page'};
+ push @pages, {'type' => 'page',
+ 'extra' => {'element' => $element}};
+ if (scalar(@pages) > 1) {
+ $pages[-1]->{'page_prev'} = $pages[-2];
+ $pages[-2]->{'page_next'} = $pages[-1];
+ }
}
push @{$pages[-1]->{'contents'}}, $element;
$element->{'parent'} = $pages[-1];
@@ -638,6 +650,102 @@
return address@hidden;
}
+sub element_directions($$)
+{
+ my $self = shift;
+ my $elements = shift;
+ return if (!$elements or address@hidden);
+
+ my $node_top = $self->{'labels'}->{'Top'};
+ foreach my $element (@$elements) {
+ my $directions;
+ $directions->{'This'} = $element;
+ $directions->{'Forward'} = $element->{'extra'}->{'element_next'}
+ if ($element->{'extra'}->{'element_next'});
+ $directions->{'Back'} = $element->{'extra'}->{'element_prev'}
+ if ($element->{'extra'}->{'element_prev'});
+ if ($element->{'node'}) {
+ my $node = $element->{'node'};
+ foreach my $direction(['NodeUp', 'node_up'], ['NodeNext', 'node_next'],
+ ['NodePrev', 'node_prev']) {
+ $directions->{$direction->[0]} = $node->{$direction->[1]}->{'parent'}
+ if ($node->{$direction->[1]});
+ }
+ my $automatic_directions =
+ (scalar(@{$node->{'extra'}->{'nodes_manuals'}}) == 1);
+ if ($node->{'menu_child'}) {
+ $directions->{'NodeForward'} = $node->{'menu_child'}->{'parent'};
+ } elsif ($automatic_directions and $node->{'associated_section'}
+ and $node->{'associated_section'}->{'section_childs'}
+ and $node->{'associated_section'}->{'section_childs'}->[0]) {
+ $directions->{'NodeForward'}
+ = $node->{'associated_section'}->{'section_childs'}->[0]->{'parent'};
+ } elsif ($node->{'node_next'}) {
+ $directions->{'NodeForward'} = $node->{'node_next'}->{'parent'};
+ } else {
+ my $up = $node->{'node_up'};
+ my @up_list = ($node);
+ # the condition with the up_list avoids infinite loops
+ # the last condition stops when the Top node is reached.
+ while (defined($up)
+ and not (grep {$up eq $_} @up_list
+ or ($node_top and $up eq $node_top))) {
+ if (defined($up->{'node_next'})) {
+ $directions->{'NodeForward'} = $up->{'node_next'}->{'parent'};
+ last;
+ }
+ push @up_list, $up;
+ $up = $up->{'node_up'};
+ }
+ }
+
+ $directions->{'NodeForward'}->{'extra'}->{'directions'}->{'NodeBack'} =
$element
+ if ($directions->{'NodeForward'}
+ and
!$directions->{'NodeForward'}->{'extra'}->{'directions'}->{'NodeBack'});
+ }
+ if ($element->{'section'}) {
+ my $section = $element->{'section'};
+ foreach my $direction(['Up', 'section_up'], ['Next', 'section_next'],
+ ['Prev', 'section_prev']) {
+ $directions->{$direction->[0]} =
$section->{$direction->[1]}->{'parent'}
+ if ($section->{$direction->[1]});
+ }
+
+ my $up = $section;
+ while ($up->{'level'} > 1 and $up->{'section_up'}) {
+ $up = $up->{'section_up'};
+ }
+ # fastforward is the next element on same level than the upper parent
+ # element.
+ # FIXME only for top and not for parts?
+ if ($up->{'level'} < 1) {
+ if ($up->{'section_childs'} and @{$up->{'section_childs'}}) {
+ $directions->{'FastForward'} =
$up->{'section_childs'}->[0]->{'parent'};
+ }
+ } else {
+ $directions->{'FastForward'} = $up->{'section_next'}->{'parent'}
+ if ($up->{'section_next'});
+ }
+ # if the element isn't at the highest level, fastback is the
+ # highest parent element
+ if ($up and $up ne $section) {
+ $directions->{'FastBack'} = $up->{'parent'};
+ } elsif ($section->{'level'} <= 1) {
+ # the element is a top level element, we adjust the next
+ # toplevel element fastback
+ $directions->{'FastForward'}->{'extra'}->{'directions'}->{'FastBack'}
+ = $section if ($directions->{'FastForward'});
+ }
+ if ($element->{'extra'}->{'directions'}) {
+ %{$element->{'extra'}->{'directions'}} =
(%{$element->{'extra'}->{'directions'}},
+ %$directions)
+ } else {
+ $element->{'extra'}->{'directions'} = $directions;
+ }
+ }
+ }
+}
+
# this is used in the test suite, but not likely to be useful in real life.
sub _unsplit($)
{
Index: Convert/HTML.pm
===================================================================
RCS file: /sources/texinfo/texinfo/tp/Texinfo/Convert/HTML.pm,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -b -r1.10 -r1.11
--- Convert/HTML.pm 6 Apr 2011 23:48:53 -0000 1.10
+++ Convert/HTML.pm 7 Apr 2011 23:08:04 -0000 1.11
@@ -155,10 +155,10 @@
'ENABLE_ENCODING' => 1,
'SHOW_MENU' => 1,
'footnotestyle' => 'end',
-# 'perl_encoding' => 'ascii',
-# 'encoding_name' => 'us-ascii',
- 'encoding_name' => undef,
- 'perl_encoding' => undef,
+ 'perl_encoding' => 'utf8',
+ 'encoding_name' => 'utf-8',
+ #'encoding_name' => undef,
+ #'perl_encoding' => undef,
'OUTFILE' => undef,
'SUBDIR' => undef,
'documentlanguage' => undef,
@@ -190,6 +190,13 @@
'DOCTYPE' => '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01
Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">',
'BODYTEXT' => undef,
'documentlanguage' => 'en',
+ 'SHOW_TITLE' => 1,
+ 'SHOW_MENU' => 1,
+# This is the default, mainly for tests; the caller should set them. These
+# values are in fact what should be set -- for now when TEST is true.
+ 'PROGRAM_AND_VERSION' => 'texi2html',
+ 'PROGRAM_HOMEPAGE' => 'http://www.gnu.org/software/texinfo/',
+ 'PROGRAM' => 'texi2html',
'DEBUG' => 0,
@@ -832,6 +839,10 @@
}
# FIXME also convert to html, to use name in cross-refs or do it on demand?
+# This set 2 unrelated things.
+# * The targets and id of sectioning elements
+# * the target, id and normalized filename of 'labels', ie everything that
+# may be the target of a ref, like @node, @float, @anchor...
sub _set_root_commands_targets_node_files($$)
{
my $self = shift;
@@ -925,35 +936,47 @@
{
my $self = shift;
my $current = shift;
+ my ($element, $root_command);
while (1) {
- if ($current->{'type'} and $current->{'type'} eq 'page') {
- return $current;
+ if ($current->{'type'}) {
+ if ($current->{'type'} eq 'page') {
+ return ($current, $element, $root_command);
+ } elsif ($current->{'type'} eq 'element') {
+ $element = $current;
+ }
}
if ($current->{'cmdname'}) {
- if ($region_commands{$current->{'cmdname'}}) {
+ if ($root_commands{$current->{'cmdname'}}) {
+ $root_command = $current;
+ } elsif ($region_commands{$current->{'cmdname'}}) {
if ($current->{'cmdname'} eq 'copying'
and $self->{'extra'} and $self->{'extra'}->{'insertcopying'}) {
foreach my $insertcopying(@{$self->{'extra'}->{'insertcopying'}}) {
- my $page = $self->_get_page($insertcopying);
- return $page if (defined($page));
+ my ($page, $element, $root_command)
+ = $self->_get_page($insertcopying);
+ return ($page, $element, $root_command)
+ if (defined($page) or defined($root_command));
}
} elsif ($current->{'cmdname'} eq 'titlepage'
and $self->get_conf('USE_TITLEPAGE_FOR_TITLE')
and $self->get_conf('SHOW_TITLE')
and $self->{'pages'}->[0]) {
- return $self->{'pages'}->[0];
- }
- return undef;
+ # FIXME element and root_command?
+ return ($self->{'pages'}->[0]);
}
- if ($current->{'cmdname'} eq 'footnote'
+ die "Problem $element, $root_command" if (defined($element)
+ or defined($root_command));
+ return (undef, undef, undef);
+ } elsif ($current->{'cmdname'} eq 'footnote'
and $self->get_conf('footnotestyle') eq 'separate') {
- return $self->{'special_pages'}->{'footnotes'};
+ # FIXME element and root_command?
+ return ($self->{'special_pages'}->{'footnotes'});
}
}
if ($current->{'parent'}) {
$current = $current->{'parent'};
} else {
- return undef;
+ return (undef, $element, $root_command);
}
}
}
@@ -973,7 +996,7 @@
# first determine the top node file name.
if ($self->get_conf('NODE_FILENAMES') and $node_top) {
if (defined($self->get_conf('TOP_NODE_FILE'))) {
- my $node_top_page = $self->_get_page($node_top);
+ my ($node_top_page) = $self->_get_page($node_top);
die "BUG: No page for top node" if (!defined($node_top));
my $filename = $self->get_conf('TOP_NODE_FILE');
$filename .= '.'.$self->get_conf('NODE_FILE_EXTENSION')
@@ -1055,6 +1078,84 @@
return $elements;
}
+my %valid_types = (
+ 'href' => 1,
+ 'string' => 1,
+ 'text' => 1,
+);
+
+# FIXME global targets
+sub _element_direction($$$$;$)
+{
+ my $self = shift;
+ my $element = shift;
+ my $direction = shift;
+ my $type = shift;
+ my $filename = shift;
+
+ my $command;
+ my $target;
+
+ if (!$valid_types{$type}) {
+ print STDERR "Incorrect type $type in _element_direction call\n";
+ return undef;
+ }
+
+ if ($element->{'extra'} and $element->{'extra'}->{'directions'}
+ and $element->{'extra'}->{'directions'}->{$direction}
+ and
$self->{'targets'}->{$element->{'extra'}->{'directions'}->{$direction}})
+ {
+ $command
+ = $element->{'extra'}->{'directions'}->{$direction}->{'element_command'};
+ $target =
+ $self->{'targets'}->{$element->{'extra'}->{'directions'}->{$direction}};
+ } else {
+ return undef;
+ }
+
+ if ($type eq 'href') {
+ my $href = '';
+ if (defined($target->{'filename'}) and
+ (!defined($filename)
+ or $filename ne $target->{'filename'})) {
+ $href .= $target->{'filename'};
+ }
+ $href .= '#' . $target->{'target'}
+ if (defined($target->{'target'}));
+ } elsif (exists($target->{$type})) {
+ return $target->{$type};
+ } elsif ($command) {
+
+ my $tree;
+ if (!$target->{'tree'}) {
+ if ($command->{'cmdname'} eq 'node') {
+ $tree = {'contents' => $command->{'extra'}->{'node_content'}};
+ } else {
+ # FIXME number
+ $tree = {'contents' => $command->{'extra'}->{'misc_content'}};
+ }
+ $target->{'tree'} = $tree;
+ } else {
+ $tree = $target->{'tree'};
+ }
+
+ return $target->{'tree'} if ($type eq 'tree');
+ push @{$self->{'context'}},
+ {'cmdname' => $command->{'cmdname'}};
+ if ($type eq 'string') {
+ $self->{'context'}->[-1]->{'string'} = 1;
+ }
+ my $content;
+ if ($command->{'cmdname'} eq 'node') {
+ $self->{'context'}->[-1]->{'code'} = 1;
+ }
+ $target->{$type} =
+ $self->_convert($tree);
+ pop @{$self->{'context'}},
+ return $target->{$type};
+ }
+}
+
# FIXME object oriented API for elements?
sub begin_file($$$)
{
@@ -1066,19 +1167,21 @@
my $title;
- # FIXME
- # if ($page and $page->{'contents'}->[0]) {
- # my $element
- # = Texinfo::Convert::HTML::Element::new($self,
$page->{'contents'}->[0]);
- # my $element_string = $selement->string();
- # if ($element_string ne $self->{'title_string'}) {
- # my $title_tree = $self->gdt('{title}: {element_text}',
- # $self->{'title_tree'}, $selement->tree());
- # $self->{'context'}->[-1]->{'string'} = 1;
- # $title = $self->_convert($title_tree);
- # delete $self->{'context'}->[-1]->{'string'};
- # }
- # }
+ # FIXME this does not work
+ if ($page and $page->{'extra'} and $page->{'extra'}->{'element'}) {
+ my $element_string =
$self->_element_direction($page->{'extra'}->{'element'},
+ 'This', 'string');
+ if (defined($element_string)
+ and $element_string ne $self->{'title_string'}) {
+ my $title_tree = $self->gdt('{title}: {element_text}',
+ $self->{'title_tree'},
+ $self->_element_direction($page->{'extra'}->{'element'},
+ 'This', 'tree'));
+ $self->{'context'}->[-1]->{'string'} = 1;
+ $title = $self->_convert($title_tree);
+ delete $self->{'context'}->[-1]->{'string'};
+ }
+ }
$title = $self->{'title_string'} if (!defined($title));
my $description;
@@ -1136,9 +1239,9 @@
my $extra_head = '';
$extra_head = $self->get_conf('EXTRA_HEAD')
if (defined($self->get_conf('EXTRA_HEAD')));
- my $program_and_version = ''; # $Texi2HTML::THISDOC{'program_and_version'}
- my $program_homepage = ''; # $Texi2HTML::THISDOC{'program_homepage'}
- my $program = ''; # $Texi2HTML::THISDOC{'program'}
+ my $program_and_version = $self->get_conf('PROGRAM_AND_VERSION');
+ my $program_homepage = $self->get_conf('PROGRAM_HOMEPAGE');
+ my $program = $self->get_conf('PROGRAM');
my $result = "$doctype
<html>
@@ -1239,8 +1342,10 @@
# determine file names associated with the different pages.
$self->_set_page_files($pages);
- # Before that, set multiple commands
+ # Add element directions
+ Texinfo::Structuring::element_directions($self, $elements);
+ # FIXME Before that, set multiple commands
$self->set_conf('BODYTEXT', 'lang="' . $self->get_conf('documentlanguage')
. '" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080"
alink="#FF0000"');
- texinfo/tp/Texinfo Common.pm Structuring.pm Con...,
Patrice Dumas <=