[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Xhtmltools-devel] Changes to xhtmltools/bin/xhtml2latex
From: |
Jaime E. Villate |
Subject: |
[Xhtmltools-devel] Changes to xhtmltools/bin/xhtml2latex |
Date: |
Fri, 29 Mar 2002 06:31:21 -0500 |
Index: xhtmltools/bin/xhtml2latex
diff -c xhtmltools/bin/xhtml2latex:1.6 xhtmltools/bin/xhtml2latex:1.7
*** xhtmltools/bin/xhtml2latex:1.6 Wed Feb 20 16:26:40 2002
--- xhtmltools/bin/xhtml2latex Fri Mar 29 06:31:18 2002
***************
*** 1,9 ****
! #! /bin/sh
! # $Id: xhtml2latex,v 1.6 2002/02/20 21:26:40 villate Exp $
#
! # xhtml2latex - creates a LaTeX file from an XHTML file
#
! # Copyright (C) 2001, 2002, Jaime Villate <address@hidden>
#
# This program is part of xhtmltools
#
--- 1,9 ----
! #! /usr/bin/perl
! # $Id: xhtml2latex,v 1.7 2002/03/29 11:31:18 villate Exp $
#
! # xhtml2latex - creates a Latex file from an XML source, using an XSLT file.
#
! # Copyright (C) 2001, 2002 Jaime Villate <address@hidden>
#
# This program is part of xhtmltools
#
***************
*** 21,118 ****
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
! XSLTLATEX='/usr/share/sgml/xhtmltools/xhtml2latex.xsl'
! TMP=XHTML2LATEX-TEMP-$$
! PARSER='xsltproc -nonet $XSLT $XHTML'
! CONFFILE=~/.xhtmltools-conf
!
! usage() {
! echo "Usage:" 1>&2
! echo " `basename $0` [-s stylesheet] [-c config] xhtmlfile" 1>&2
! echo " " 1>&2
! exit 1
! }
!
! [[ $# -lt 1 ]] && usage
!
! while [[ $# -gt 0 ]]
! do
! case $1 in
! -s) STYLESHEET=$2
! shift
! ;;
! -h|--help)
! usage
! ;;
! -c) CONFFILE=$2
! shift
! ;;
! -*)
! usage
! ;;
! *)
! XHTMLFILE=$1
! esac
! shift
! done
!
! [[ -n $XHTMLFILE ]] || usage
!
! [[ -r $CONFFILE ]] && source $CONFFILE
!
! XSLTDIR=$(dirname $XSLTLATEX)
!
! if [[ -n $STYLESHEET ]]
! then
! if [[ -r $STYLESHEET ]]
! then
! XSLT=$STYLESHEET
! elif [[ -r $XSLTDIR/$STYLESHEET ]]
! then
! XSLT=$XSLTDIR/$STYLESHEET
! else
! XSLT=$STYLESHEET
! fi
! else
! XSLT=$XSLTLATEX
! fi
!
! if [[ ! -r $XSLT ]]
! then
! echo Cannot find stylesheet \"$XSLT\" >&2
! exit 1
! fi
! if [[ ! -r $XHTMLFILE ]]
! then
! echo Cannot read XHTML file \"$1\" >&2
! exit 1
! fi
!
! perl -pe '$f=1 if (/<body/);
! $f=0 if (/<\/body>/);
! $f=0 if (/<pre>/);
! $f=1 if (/<\/pre>/);
! if ($f==1) {
! s/\\/\\ensuremath{\\backslash}/g;
! s/&/\\&/g;
! s/#/\\#/g;
! s/%/\\%/g;
! s/_/\\_/g;
! s/\{/\\{/g;
! s/\}/\\}/g;
! s/\$/\\\$/g;
! s/\^/\\^{}/g;
! s/~/\\~{}/g;
! s/>/\\ensuremath{>}/g;
! s/</\\ensuremath{<}/g;
! while (/(href=\"[^\"]*)\\/)
{
! s/(href=\"[^\"]*)\\/$1/g;
}
! }' $XHTMLFILE > $TMP
! XHTML=$TMP
! (eval $PARSER | sed "s/\\href{\#/\\hyperlink{/") || (rm -f $TMP; exit 1)
! rm -f $TMP
! exit 0
--- 21,144 ----
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ # Default configuration
+ my $tmp="XHTML2HTML-TEMP-$$";
+ my $conffile="$ENV{HOME}/.xhtmltools";
+ my $stylesheet;
+ my $config = '';
+
+ # parse command line options
+ while ($_ = $ARGV[0], /^-/)
+ {
+ shift;
+ if (/^-s/) { $stylesheet = shift }
+ if (/^(-h|--help)/) { &usage }
+ if (/^-c/) { $conffile = shift }
+ }
+ unshift(@ARGV, '-') unless @ARGV;
+ &usage if ($#ARGV > 0);
+ my $xmlfile = shift;
+ $xmlfile = '-' unless $xmlfile;
+
+ # process configuration file
+ if (-r $conffile)
+ {
+ open (CNF, "<$conffile");
+ undef $/;
+ $config = <CNF>;
+ close CNF;
+ } else {
+ print STDERR "$0:\n\tConfiguration file $conffile cannot be read.\n";
+ print STDERR "\tYou should prepare a configuration file and\n";
+ print STDERR "\tif it's not in the default location ~/.xhtmltools,\n";
+ print STDERR "\tuse option -c to specify its location.\n\n";
+ exit 1;
+ }
+ $config =~ s/\n/ /g;
+ my $parser = &getnode('xsltparser',\$config);
+ $stylesheet = &getnode('latexstylesheet',\$config) unless $stylesheet;
+
+ # Check whether stylesheet is readable
+ unless (-r $stylesheet)
+ {
+ print STDERR "$0:\n\tCannot read stylesheet $stylesheet\n\n";
+ exit 1;
+ }
+
+ # Check whether input file is readable
+ unless (-r $xmlfile || $xmlfile eq '-')
+ {
+ print STDERR "$0:\n\tCannot read file $xmlfile\n\n";
+ exit 1;
+ }
! # Create temporary file
! open (TMP,">$tmp") or die "$0:\n\tCannot create temporary file\n\n";
! open (IN,"<$xmlfile") or die "$0:\n\tCannot read the input file\n\n" ;
! $/ = "\n";
! my $f;
! while (<IN>)
! {
! # write a pointer to the configuration file
! s/<\/head>/<meta name="configuration" content="$conffile" \/>\n<\/head>/;
! $f=1 if (/<body/);
! $f=0 if (/<\/body>/);
! $f=0 if (/<pre>/);
! $f=1 if (/<\/pre>/);
! if ($f==1)
{
! # Protect Latex special characters
! s/\\/\\ensuremath{\\backslash}/g;
! s/&/\\&/g;
! s/#/\\#/g;
! s/%/\\%/g;
! s/_/\\_/g;
! s/\{/\\{/g;
! s/\}/\\}/g;
! s/\$/\\\$/g;
! s/\^/\\^{}/g;
! s/~/\\~{}/g;
! s/>/\\ensuremath{>}/g;
! s/</\\ensuremath{<}/g;
! while (/(href=\"[^\"]*)\\/)
! {
! s/(href=\"[^\"]*)\\/$1/g;
! }
}
! print TMP;
! }
! close IN;
! close TMP;
!
! # prepare xslt parser command-line
! my $XSLT = $stylesheet;
! my $XHTML = $tmp;
! my $xsltparser = eval "qq{$parser}";
!
! # parse the XHTML file
! system qq($xsltparser| sed "s/\\href{\#/\\hyperlink{/") ||
! (system("rm -f $tmp"), exit 1);
! system("rm -f $tmp");
!
! exit 0;
!
! # Function to display a program usage summary
! sub usage
! {
! print STDERR "Usage:\n";
! print STDERR "$0 [-s stylesheet] [-c config] [xmlfile]\n\n";
! exit 1;
! }
! # Function to extract the contents of an XML element
! sub getnode
! {
! my $element = shift;
! my $config = shift;
! $$config =~ /<$element>(.*)<\/$element>/;
! my $node = $1;
! $node =~ s/<[^>]*>//g;
! $node =~ s/^\s*//;
! $node =~ s/\s*$//;
! return $node;
! }
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Xhtmltools-devel] Changes to xhtmltools/bin/xhtml2latex,
Jaime E. Villate <=