[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
texinfo/tp/Texinfo/Convert Converter.pm DocBook...
From: |
Patrice Dumas |
Subject: |
texinfo/tp/Texinfo/Convert Converter.pm DocBook... |
Date: |
Sat, 17 Sep 2011 22:31:55 +0000 |
CVSROOT: /sources/texinfo
Module name: texinfo
Changes by: Patrice Dumas <pertusus> 11/09/17 22:31:55
Modified files:
tp/Texinfo/Convert: Converter.pm DocBook.pm XML.pm
Log message:
Sync DocBook with relevant things in XML.
Factor out some code.
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/Texinfo/Convert/Converter.pm?cvsroot=texinfo&r1=1.39&r2=1.40
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/Texinfo/Convert/DocBook.pm?cvsroot=texinfo&r1=1.7&r2=1.8
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/Texinfo/Convert/XML.pm?cvsroot=texinfo&r1=1.37&r2=1.38
Patches:
Index: Converter.pm
===================================================================
RCS file: /sources/texinfo/texinfo/tp/Texinfo/Convert/Converter.pm,v
retrieving revision 1.39
retrieving revision 1.40
diff -u -b -r1.39 -r1.40
--- Converter.pm 17 Sep 2011 21:23:59 -0000 1.39
+++ Converter.pm 17 Sep 2011 22:31:55 -0000 1.40
@@ -542,6 +542,37 @@
return $command;
}
+# output fo $fh if defined, otherwise return the text.
+sub _output_text($$)
+{
+ my $text = shift;
+ my $fh = shift;
+ if ($fh) {
+ print $fh $text;
+ return '';
+ } else {
+ return $text;
+ }
+}
+
+sub _convert_document_sections($$;$)
+{
+ my $self = shift;
+ my $root = shift;
+ my $fh = shift;
+
+ my $result = '';
+ my $elements = Texinfo::Structuring::split_by_section($root);
+ if ($elements) {
+ foreach my $element (@$elements) {
+ $result .= _output_text ($self->_convert($element), $fh);
+ }
+ return $result;
+ } else {
+ return _output_text ($self->_convert($root), $fh);
+ }
+}
+
my @inline_types = ('def_line', 'paragraph', 'preformatted',
'misc_command_arg', 'misc_line_arg', 'block_line_arg',
'menu_entry_name', 'menu_entry_node');
Index: DocBook.pm
===================================================================
RCS file: /sources/texinfo/texinfo/tp/Texinfo/Convert/DocBook.pm,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -b -r1.7 -r1.8
--- DocBook.pm 17 Sep 2011 00:23:13 -0000 1.7
+++ DocBook.pm 17 Sep 2011 22:31:55 -0000 1.8
@@ -325,24 +325,14 @@
return $elements;
}
-sub convert($$)
+sub convert($$;$)
{
my $self = shift;
my $root = shift;
+ my $fh = shift;
my $elements = $self->_initialize_document($root);
-
- my $result = '';
- if (!defined($elements)) {
- $result = $self->_convert($root);
- } else {
- foreach my $element (@$elements) {
- my $element_text = $self->_convert($element);
- $result .= $element_text;
- }
- }
-
- return $result;
+ return $self->_convert_document_sections($root, $fh);
}
sub _normalize_top_node($)
@@ -351,19 +341,6 @@
return Texinfo::Common::normalize_top_node($node);
}
-# output fo $fh if defined, otherwise return the text.
-sub _output_text($$)
-{
- my $text = shift;
- my $fh = shift;
- if ($fh) {
- print $fh $text;
- return '';
- } else {
- return $text;
- }
-}
-
sub output($$)
{
my $self = shift;
@@ -401,16 +378,9 @@
'. "<book${id} lang=\"".$self->get_conf('documentlanguage') ."\">\n";
my $result = '';
- $result .= _output_text($header, $fh);
- if (!defined($elements)) {
- $result .= _output_text($self->_convert($root), $fh);
- } else {
- foreach my $element (@$elements) {
- $result .= _output_text($self->_convert($root), $fh);
- }
- }
-
- $result .= _output_text("</book>\n", $fh);
+ $result .= Texinfo::Convert::Converter::_output_text($header, $fh);
+ $result .= $self->convert($root, $fh);
+ $result .= Texinfo::Convert::Converter::_output_text("</book>\n", $fh);
return $result;
}
@@ -1225,9 +1195,21 @@
if ($context_block_commands{$root->{'cmdname'}}) {
pop @{$self->{'document_context'}};
}
- } elsif ($root->{'cmdname'}
+ # The command is closed either when the corresponding tree element
+ # is done, and the command is not associated to an element, or when
+ # the element is closed.
+ } elsif (($root->{'type'} and $root->{'type'} eq 'element'
+ and $root->{'extra'} and $root->{'extra'}->{'element_command'})
+ or ($root->{'cmdname'}
and $Texinfo::Common::root_commands{$root->{'cmdname'}}
- and $root->{'cmdname'} ne 'node') {
+ and $root->{'cmdname'} ne 'node'
+ and !($root->{'parent'} and $root->{'parent'}->{'type'}
+ and $root->{'parent'}->{'type'} eq 'element'
+ and $root->{'parent'}->{'extra'}
+ and $root->{'parent'}->{'extra'}->{'element_command'} eq
$root))) {
+ if ($root->{'type'} and $root->{'type'} eq 'element') {
+ $root = $root->{'extra'}->{'element_command'};
+ }
my $command = $self->_docbook_section_element($root);
my $command_texi = $self->_level_corrected_section($root);
if (!($root->{'section_childs'} and scalar(@{$root->{'section_childs'}}))
Index: XML.pm
===================================================================
RCS file: /sources/texinfo/texinfo/tp/Texinfo/Convert/XML.pm,v
retrieving revision 1.37
retrieving revision 1.38
diff -u -b -r1.37 -r1.38
--- XML.pm 17 Sep 2011 21:34:25 -0000 1.37
+++ XML.pm 17 Sep 2011 22:31:55 -0000 1.38
@@ -310,18 +310,10 @@
}
my $result = '';
- if ($fh) {
- print $fh $header;
- } else {
- $result .= $header;
- }
+ $result .= Texinfo::Convert::Converter::_output_text($header, $fh);
$result .= $self->convert($root, $fh);
- my $footer = "</texinfo>\n";
- if ($fh) {
- print $fh $footer;
- } else {
- $result .= $footer;
- }
+ $result .= Texinfo::Convert::Converter::_output_text("</texinfo>\n", $fh);
+
return $result;
}
@@ -365,23 +357,7 @@
my $root = shift;
my $fh = shift;
- my $result = '';
- my $elements = Texinfo::Structuring::split_by_section($root);
- if ($elements) {
- foreach my $element (@$elements) {
- if ($fh) {
- print $fh $self->_convert($element);
- } else {
- $result .= $self->_convert($element);
- }
- }
- return $result;
- } elsif ($fh) {
- print $fh $self->_convert($root);
- return '';
- } else {
- return $self->_convert($root);
- }
+ return $self->_convert_document_sections($root, $fh);
}
sub _convert($$;$);