texinfo-commits
[Top][All Lists]
Advanced

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

texinfo/tp/Texinfo Common.pm Convert/Converter....


From: Patrice Dumas
Subject: texinfo/tp/Texinfo Common.pm Convert/Converter....
Date: Mon, 28 Mar 2011 23:52:37 +0000

CVSROOT:        /sources/texinfo
Module name:    texinfo
Changes by:     Patrice Dumas <pertusus>        11/03/28 23:52:37

Modified files:
        tp/Texinfo     : Common.pm 
        tp/Texinfo/Convert: Converter.pm HTML.pm 

Log message:
        Mark alignement commands.
        Many fixes to HTML.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/Texinfo/Common.pm?cvsroot=texinfo&r1=1.27&r2=1.28
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/Texinfo/Convert/Converter.pm?cvsroot=texinfo&r1=1.5&r2=1.6
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/Texinfo/Convert/HTML.pm?cvsroot=texinfo&r1=1.1&r2=1.2

Patches:
Index: Common.pm
===================================================================
RCS file: /sources/texinfo/texinfo/tp/Texinfo/Common.pm,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -b -r1.27 -r1.28
--- Common.pm   27 Mar 2011 22:55:13 -0000      1.27
+++ Common.pm   28 Mar 2011 23:52:37 -0000      1.28
@@ -418,8 +418,15 @@
   $block_commands{$menu_command} = 0;
 };
 
+our %align_commands;
+foreach my $align_command('raggedright', 'flushleft', 'flushright') {
+  $block_commands{$align_command} = 0;
+  $align_commands{$align_command} = 1;
+}
+$align_commands{'center'} = 1;
+
 foreach my $block_command(
-    'cartouche', 'group', 'raggedright', 'flushleft', 'flushright') {
+    'cartouche', 'group') {
   $block_commands{$block_command} = 0;
 }
 
@@ -429,19 +436,19 @@
   $region_commands{$block_command} = 1;
 }
   
-
 our %preformatted_commands;
+our %preformatted_code_commands;
 foreach my $preformatted_command(
-    'example', 'smallexample', 'display', 'smalldisplay', 'lisp',
-    'smalllisp', 'format', 'smallformat') {
+    'example', 'smallexample', 'lisp', 'smalllisp') {
   $block_commands{$preformatted_command} = 0;
   $preformatted_commands{$preformatted_command} = 1;
+  $preformatted_code_commands{$preformatted_command} = 1;
 }
 
-our %preformatted_code_commands;
 foreach my $preformatted_command(
-    'example', 'smallexample', 'lisp', 'smalllisp') {
-  $preformatted_code_commands{$preformatted_command} = 1;
+    'display', 'smalldisplay', 'format', 'smallformat') {
+  $block_commands{$preformatted_command} = 0;
+  $preformatted_commands{$preformatted_command} = 1;
 }
 
 our %raw_commands;

Index: Convert/Converter.pm
===================================================================
RCS file: /sources/texinfo/texinfo/tp/Texinfo/Convert/Converter.pm,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -b -r1.5 -r1.6
--- Convert/Converter.pm        27 Mar 2011 22:55:13 -0000      1.5
+++ Convert/Converter.pm        28 Mar 2011 23:52:37 -0000      1.6
@@ -359,9 +359,9 @@
                'guilsinglright'          => '&rsaquo;',
 };
 
-foreach my $text_no_brace_commands 
(keys(%Texinfo::Convert::Text::text_no_brace_commands)) {
-  $default_xml_commands_formatting{'normal'}->{$text_no_brace_commands}
-    = $Texinfo::Convert::Text::text_no_brace_commands{$text_no_brace_commands};
+foreach my $text_no_brace_command 
(keys(%Texinfo::Convert::Text::text_no_brace_commands)) {
+  $default_xml_commands_formatting{'normal'}->{$text_no_brace_command}
+    = $Texinfo::Convert::Text::text_no_brace_commands{$text_no_brace_command};
 }
 
 my %xml_accent_entities = (
@@ -403,8 +403,8 @@
   if ($use_numeric_entities
       and exists($Texinfo::Convert::unicode_accented_letters{$accent}) 
       and 
exists($Texinfo::Convert::unicode_accented_letters{$accent}->{$text})) {
-    return ('&#' . 
-      hex($Texinfo::Convert::unicode_accented_letters{$accent}->{$text}). ';');
+    return '&#' . 
+      hex($Texinfo::Convert::unicode_accented_letters{$accent}->{$text}). ';';
   }
   return $text . '&lt;' if ($accent eq 'v');
   return Texinfo::Convert::Text::ascii_accent($text, $command);

Index: Convert/HTML.pm
===================================================================
RCS file: /sources/texinfo/texinfo/tp/Texinfo/Convert/HTML.pm,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- Convert/HTML.pm     27 Mar 2011 22:55:13 -0000      1.1
+++ Convert/HTML.pm     28 Mar 2011 23:52:37 -0000      1.2
@@ -57,7 +57,7 @@
 # misc commands that are of use for formatting.
 my %formatting_misc_commands = 
%Texinfo::Convert::Text::formatting_misc_commands;
 my %text_no_brace_commands = %Texinfo::Convert::Text::text_no_brace_commands;
-my %no_brace_commands = %Texinfo::Convert::Text::no_brace_commands;
+my %no_brace_commands = %Texinfo::Common::no_brace_commands;
 my %text_brace_no_arg_commands = 
%Texinfo::Convert::Text::text_brace_no_arg_commands;
 my %accent_commands = %Texinfo::Common::accent_commands;
 my %misc_commands = %Texinfo::Common::misc_commands;
@@ -77,11 +77,77 @@
 my %preformatted_code_commands = %Texinfo::Common::preformatted_code_commands;
 my %default_index_commands = %Texinfo::Common::default_index_commands;
 my %style_commands = %Texinfo::Common::style_commands;
+my %align_commands = %Texinfo::Common::align_commands;
 
 foreach my $def_command (keys(%def_commands)) {
   $formatting_misc_commands{$def_command} = 1 if 
($misc_commands{$def_command});
 }
 
+# FIXME remove raw commands?
+my %format_context_commands = (%block_commands, %root_commands);
+
+foreach my $misc_context_command('tab', 'item', 'itemx', 'headitem', 'math') {
+  $format_context_commands{$misc_context_command} = 1;
+}
+
+# FIXME allow customization?
+my %upper_case_commands = ( 'sc' => 1 );
+
+sub in_math($)
+{
+  my $self = shift;
+  return $self->{'context'}->[-1]->{'math'};
+}
+
+sub in_preformatted($)
+{
+  my $self = shift;
+  return $self->{'context'}->[-1]->{'preformatted'};
+}
+
+sub in_upper_case($)
+{
+  my $self = shift;
+  return $self->{'context'}->[-1]->{'upper_case'};
+}
+
+sub in_space_protected($)
+{
+  my $self = shift;
+  return $self->{'context'}->[-1]->{'space_protected'};
+}
+
+sub in_code($)
+{
+  my $self = shift;
+  return $self->{'context'}->[-1]->{'code'};
+}
+
+sub in_string($)
+{
+  my $self = shift;
+  return $self->{'context'}->[-1]->{'string'};
+}
+
+sub paragraph_number($)
+{
+  my $self = shift;
+  return $self->{'context'}->[-1]->{'paragraph_number'};
+}
+
+sub top_format($)
+{
+  my $self = shift;
+  return $self->{'context'}->[-1]->{'formats'};
+}
+
+sub align($)
+{  
+  my $self = shift;
+  return $self->{'context'}->[-1]->{'align'};
+}
+
+
 
 my %defaults = (
   'ENABLE_ENCODING'      => 1,
@@ -223,11 +289,11 @@
 
 foreach my $command (keys(%{$default_commands_formatting{'normal'}})) {
   $default_commands_formatting{'preformatted'}->{$command} = 
-     $default_commands_formatting{'normal'}->{$command} 
-       unless exists($default_commands_formatting{'preformatted'}->{$command});
+     $default_commands_formatting{'normal'}->{$command};
+#       unless 
exists($default_commands_formatting{'preformatted'}->{$command});
   $default_commands_formatting{'string'}->{$command} =
-     $default_commands_formatting{'normal'}->{$command} 
-       unless exists($default_commands_formatting{'string'}->{$command});
+     $default_commands_formatting{'normal'}->{$command};
+#       unless exists($default_commands_formatting{'string'}->{$command});
 }
 
 $default_commands_formatting{'normal'}->{'enddots'} 
@@ -376,8 +442,8 @@
   if (defined($attribute_hash->{$cmdname})) {
     if (defined($attribute_hash->{$cmdname}->{'attribute'})) {
       my ($style, $class, $attribute_text)
-        = parse_attribute ($attribute_hash->{$cmdname}->{'attribute'});
-      $text = attribute_class($style, $class) . "$attribute_text>" 
+        = _parse_attribute ($attribute_hash->{$cmdname}->{'attribute'});
+      $text = $self->attribute_class($style, $class) . "$attribute_text>" 
               . "$text" . "</$style>";
     }
     if (defined($attribute_hash->{$cmdname}->{'quote'})) {
@@ -399,7 +465,7 @@
 }
 
 foreach my $command (keys(%accent_commands)) {
-$default_commands_conversion{$command} = \&accent_commands;
+  $default_commands_conversion{$command} = \&accent_commands;
 }
 
 my %default_types_conversion;
@@ -427,14 +493,15 @@
   my $content = shift;
 
   if ($self->paragraph_number() == 1) {
-    my $in_format = $self->in_format();
+    my $in_format = $self->top_format();
+    # FIXME also verify that in @item/@tab/@headitem
     return $content 
       if ($in_format eq 'itemize' 
           or $in_format eq 'enumerate'
           or $in_format eq 'multitable');
   }
-  if ($self->align()) {
     my $align = $self->align();
+  if ($paragraph_style{$align}) {
     return "<p align=\"$paragraph_style{$align}\">".$content."</p>";
   } else {
     return "<p>".$content."</p>";
@@ -541,6 +608,10 @@
     }
   }
 
+  $self->{'context'} = [{'cmdname' => '_toplevel_context'}];
+  $self->{'formats'} = [];
+  $self->{'align'} = ['raggedright'];
+
   return $self;
 }
 
@@ -1066,7 +1137,29 @@
     # FIXME definfoenclose_command 
     # ($root->{'type'} and $root->{'type'} eq 'definfoenclose_command'))
     if (exists($self->{'commands_conversion'}->{$root->{'cmdname'}})) {
+      my $result;
       my $content_formatted;
+      if (exists($format_context_commands{$root->{'cmdname'}})) {
+        push @{$self->{'context'}}, {'cmdname' => $root->{'cmdname'}};
+      }
+      if (exists($block_commands{$root->{'cmdname'}})) {
+        push @{$self->{'formats'}}, $root->{'cmdname'};
+      }
+      if ($preformatted_commands{$root->{'cmdname'}}) {
+        $self->{'context'}->[-1]->{'preformatted'}++;
+      }
+      if ($code_style_commands{$root->{'cmdname'}} or 
+          $preformatted_code_commands{$root->{'cmdname'}}) {
+        $self->{'context'}->[-1]->{'code'}++;
+      } elsif ($upper_case_commands{$root->{'cmdname'}}) {
+        $self->{'context'}->[-1]->{'upper_case'}++;
+      } elsif ($root->{'cmdname'} eq 'math') {
+        $self->{'context'}->[-1]->{'math'}++;
+      } elsif ($root->{'cmdname'} eq 'w') {
+        $self->{'context'}->[-1]->{'space_protected'}++;
+      } elsif ($align_commands{$root->{'cmdname'}}) {
+        push @{$self->{'align'}}, $root->{'cmdname'};
+      }
       if ($root->{'contents'}) {
         $content_formatted = '';
         # TODO different types of contents
@@ -1087,16 +1180,41 @@
             push @$args_formatted, {'normal' => $self->_convert($arg)};
           }
         }
-        return &{$self->{'commands_conversion'}->{$root->{'cmdname'}}}($self,
+        $result = 
&{$self->{'commands_conversion'}->{$root->{'cmdname'}}}($self,
                 $root->{'cmdname'}, $root, $args_formatted, 
$content_formatted);
       } else {
-        return &{$self->{'commands_conversion'}->{$root->{'cmdname'}}}($self,
+        $result = 
&{$self->{'commands_conversion'}->{$root->{'cmdname'}}}($self,
                 $root->{'cmdname'}, $root, $content_formatted);
       }
+      if ($preformatted_commands{$root->{'cmdname'}}) {
+        $self->{'context'}->[-1]->{'preformatted'}--;
+      }
+      if ($code_style_commands{$root->{'cmdname'}} or 
+          $preformatted_code_commands{$root->{'cmdname'}}) {
+        $self->{'context'}->[-1]->{'code'}--;
+      } elsif ($upper_case_commands{$root->{'cmdname'}}) {
+        $self->{'context'}->[-1]->{'upper_case'}--;
+      } elsif ($root->{'cmdname'} eq 'math') {
+        $self->{'context'}->[-1]->{'math'}--;
+      } elsif ($root->{'cmdname'} eq 'w') {
+        $self->{'context'}->[-1]->{'space_protected'}--;
+      } elsif ($align_commands{$root->{'cmdname'}}) {
+        pop @{$self->{'align'}};
+      }
+      if (exists($block_commands{$root->{'cmdname'}})) {
+        pop @{$self->{'formats'}};
+      }
+      if (exists($format_context_commands{$root->{'cmdname'}})) {
+        pop @{$self->{'context'}};
+      }
+      return $result;
     } else {
-      print STDERR "BUG: unknown command $root->{'cmdname'}\n";
+      print STDERR "BUG: unknown command `$root->{'cmdname'}'\n";
     }
   } elsif ($root->{'type'}) {
+    if ($root->{'type'} eq 'paragraph') {
+      $self->{'context'}->[-1]->{'paragraph_number'}++;
+    }
     my $content_formatted;
     if ($root->{'contents'}) {
       $content_formatted = '';
@@ -1113,6 +1231,12 @@
     } elsif (defined($content_formatted)) {
       return $content_formatted;
     }
+  } elsif ($root->{'contents'}) {
+    my $content_formatted = '';
+    foreach my $content (@{$root->{'contents'}}) {
+      $content_formatted .= $self->_convert($content);
+    }
+    return $content_formatted;
   }
     #} elsif ($command eq 'value') {
     #  my $expansion = $self->gdt('@{No value for `{value}\'@}', 



reply via email to

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