texinfo-commits
[Top][All Lists]
Advanced

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

texinfo/tp texi2any.pl Texinfo/Common.pm Texinf...


From: Patrice Dumas
Subject: texinfo/tp texi2any.pl Texinfo/Common.pm Texinf...
Date: Tue, 15 Jan 2013 20:18:52 +0000

CVSROOT:        /sources/texinfo
Module name:    texinfo
Changes by:     Patrice Dumas <pertusus>        13/01/15 20:18:52

Modified files:
        tp             : texi2any.pl 
        tp/Texinfo     : Common.pm 
Added files:
        tp/Texinfo/Convert: SXML.pm 

Log message:
        Add a converter to SXML, a simple subclass of Texinfo::Convert::XML.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/texi2any.pl?cvsroot=texinfo&r1=1.158&r2=1.159
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/Texinfo/Common.pm?cvsroot=texinfo&r1=1.168&r2=1.169
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/Texinfo/Convert/SXML.pm?cvsroot=texinfo&rev=1.1

Patches:
Index: texi2any.pl
===================================================================
RCS file: /sources/texinfo/texinfo/tp/texi2any.pl,v
retrieving revision 1.158
retrieving revision 1.159
diff -u -b -r1.158 -r1.159
--- texi2any.pl 2 Jan 2013 17:37:48 -0000       1.158
+++ texi2any.pl 15 Jan 2013 20:18:51 -0000      1.159
@@ -101,6 +101,7 @@
 use Texinfo::Convert::Info;
 use Texinfo::Convert::HTML;
 use Texinfo::Convert::XML;
+use Texinfo::Convert::SXML;
 use Texinfo::Convert::DocBook;
 use Texinfo::Convert::TextContent;
 use Texinfo::Convert::PlainTexinfo;
@@ -825,6 +826,8 @@
        $format = set_format('rawtext', 1);
      } elsif ($var eq 'TEXTCONTENT') {
        $format = set_format('textcontent', 1);
+     } elsif ($var eq 'SXML') {
+       $format = set_format('sxml', 1);
      }
      set_from_cmdline ($var, $value);
      # FIXME do that here or when all command line options are processed?
@@ -919,6 +922,10 @@
              'nodes_tree' => 1,
              'converter' => sub{Texinfo::Convert::XML->converter(@_)},
            },
+  'sxml' => {
+             'nodes_tree' => 1,
+             'converter' => sub{Texinfo::Convert::SXML->converter(@_)},
+           },
   'docbook' => {
              'move_index_entries_after_items' => 1,
              'converter' => sub{Texinfo::Convert::DocBook->converter(@_)},

Index: Texinfo/Common.pm
===================================================================
RCS file: /sources/texinfo/texinfo/tp/Texinfo/Common.pm,v
retrieving revision 1.168
retrieving revision 1.169
diff -u -b -r1.168 -r1.169
--- Texinfo/Common.pm   7 Jan 2013 21:42:11 -0000       1.168
+++ Texinfo/Common.pm   15 Jan 2013 20:18:51 -0000      1.169
@@ -189,7 +189,8 @@
   'SPLIT_INDEX');
 
 my @formats_settable = (
-  'DEBUGCOUNT', 'DEBUGTREE', 'RAWTEXT', 'TEXTCONTENT', 'PLAINTEXINFO'
+  'DEBUGCOUNT', 'DEBUGTREE', 'RAWTEXT', 'TEXTCONTENT', 'PLAINTEXINFO',
+  'SXML',
 );
 
 my @variable_string_settables = (

Index: Texinfo/Convert/SXML.pm
===================================================================
RCS file: Texinfo/Convert/SXML.pm
diff -N Texinfo/Convert/SXML.pm
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ Texinfo/Convert/SXML.pm     15 Jan 2013 20:18:51 -0000      1.1
@@ -0,0 +1,192 @@
+# SXML.pm: output tree as SXML.
+#
+# Copyright 2013 Free Software Foundation, Inc.
+# 
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License,
+# or (at your option) any later version.
+# 
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+# 
+# Original author: Patrice Dumas <address@hidden>
+#
+# This is a simple subclass of Texinfo::Convert::XML that overrides
+# format specific functions.
+
+package Texinfo::Convert::SXML;
+
+use 5.00405;
+use strict;
+
+use Texinfo::Convert::XML;
+use Carp qw(cluck);
+
+require Exporter;
+use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
address@hidden = qw(Exporter Texinfo::Convert::XML);
+
+# Items to export into callers namespace by default. Note: do not export
+# names by default without a very good reason. Use EXPORT_OK instead.
+# Do not simply export all your public functions/methods/constants.
+
+# This allows declaration       use Texinfo::Convert::XML ':all';
+# If you do not need this, moving things directly into @EXPORT or @EXPORT_OK
+# will save memory.
+%EXPORT_TAGS = ( 'all' => [ qw(
+  convert
+  convert_tree
+  output
+) ] );
+
address@hidden = ( @{ $EXPORT_TAGS{'all'} } );
+
address@hidden = qw(
+);
+
+$VERSION = '5.0';
+
+# SXML specific
+my %defaults = (
+  'ENABLE_ENCODING'      => 0,
+  'SHOW_MENU'            => 1,
+  'EXTENSION'            => 'sxml',
+  #'output_perl_encoding' => 'utf8',
+  'OUTPUT_ENCODING_NAME' => 'utf-8',
+  'TEXINFO_DTD_VERSION'  => '5.0',
+  'OUTFILE'              => undef,
+  'SUBDIR'               => undef,
+  'output_format'        => 'sxml',
+  'SPLIT'                => 0,
+  'documentlanguage'     => 'en',
+);
+
+sub converter_defaults($$)
+{
+  return %defaults;
+}
+
+# format specific.  Used in few places where plain text is used outside
+# of attributes.
+sub protect_text($$)
+{
+  my $self = shift;
+  my $string = shift;
+  $string =~ s/\\/\\\\/g;
+  $string =~ s/"/\\"/g;
+  return $string;
+}
+
+sub sxml_attributes($$)
+{
+  my $self = shift;
+  my $attributes = shift;
+  if (ref($attributes) ne 'ARRAY') {
+    cluck "attributes not an array($attributes).";
+  }
+  my $result = '(@';
+  for (my $i = 0; $i < scalar(@$attributes); $i += 2) {
+    $result .= " ($attributes->[$i] 
\"".$self->protect_text($attributes->[$i+1])."\")";
+  }
+  return $result . ')';
+}
+
+# format specific
+sub element($$$)
+{
+  my $self = shift;
+  my $element_name = shift;
+  my $attributes = shift;
+  my $result = '('.$element_name." ";
+  $attributes = [] if (!defined($attributes));
+  $result .= $self->sxml_attributes($attributes);
+  $result .= ')';
+  return $result;
+}
+
+# format specific
+sub open_element($$$)
+{
+  my $self = shift;
+  my $element_name = shift;
+  my $attributes = shift;
+  my $result = '('.$element_name." ";
+  $attributes = [] if (!defined($attributes));
+  $result .= $self->sxml_attributes($attributes);
+  $result .= " ";
+  return $result;
+}
+
+# format specific
+sub close_element($$)
+{
+  my $self = shift;
+  my $element_name = shift;
+  my $result= ')';
+  return $result;
+}
+
+my %commands_formatting = %Texinfo::Convert::XML::commands_formatting;
+
+# format specific
+sub format_atom($$)
+{
+  my $self = shift;
+  my $atom = shift;
+  if ($commands_formatting{$atom} ne '') {
+    return '('.$commands_formatting{$atom}.' (@))';
+  } else {
+    return '';
+  }
+}
+
+# format specific
+#FIXME
+sub format_comment($$)
+{
+  my $self = shift;
+  my $string = shift;
+
+  return '';
+}
+
+# format specific
+sub format_text($$)
+{
+  my $self = shift;
+  my $root = shift;
+  my $result = $self->protect_text($root->{'text'});
+  if (! defined($root->{'type'}) or $root->{'type'} ne 'raw') {
+    if (!$self->{'document_context'}->[-1]->{'monospace'}->[-1]) {
+      $result =~ s/``/" (textldquo (@)) "/g;
+      $result =~ s/\'\'/" (textrdquo (@)) "/g;
+      $result =~ s/---/" (textmdash (@)) "/g;
+      $result =~ s/--/" (textndash (@)) "/g;
+      $result =~ s/'/" (textrsquo (@)) "/g;
+      $result =~ s/`/" (textlsquo (@)) "/g;
+    }
+  }
+  return ' "'.$result.'" ';
+}
+
+# output format specific
+sub format_header($)
+{
+  my $self = shift;
+  my $header = '';
+  my $encoding = '';
+  if ($self->get_conf('OUTPUT_ENCODING_NAME')
+      and $self->get_conf('OUTPUT_ENCODING_NAME') ne 'utf-8') {
+    $encoding = $self->get_conf('OUTPUT_ENCODING_NAME');
+  }
+  if ($self->{'output_file'} ne '') {
+    my $output_filename = $self->{'output_filename'};
+  }
+  return $header;
+}



reply via email to

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