1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/scripts/vym2html.sh Sat Mar 31 09:28:27 2007 +0000
1.3 @@ -0,0 +1,250 @@
1.4 +#!/bin/sh
1.5 +#
1.6 +# vym2html.sh
1.7 +#
1.8 +VERSION="0.7"
1.9 +# Date: 20040625
1.10 +# Author: Clemens Kraus (http://www.clemens-kraus.de)
1.11 +#
1.12 +# AddOns: Uwe Drechsel
1.13 +#echo $@
1.14 +
1.15 +
1.16 +unpacker()
1.17 +# Unpack vym-file, only if it is one
1.18 +{
1.19 + echo $VYMFILE_EXT | grep -F ".vym" 1>/dev/null
1.20 +
1.21 + if [ $? = 0 ] ; then
1.22 + echo ">> Unpacking files ..."
1.23 + unzip $VYMFILE_EXT -d $VYMPATH 1>/dev/null
1.24 + if [ $? -gt 0 ] ; then
1.25 + echo ">>> Error in unzip! Aborting."
1.26 + exit 4
1.27 + fi
1.28 + fi
1.29 +}
1.30 +
1.31 +
1.32 +transform()
1.33 +{
1.34 + # copy stylesheet
1.35 + if [ -z $STYLESHEETP ] ; then
1.36 + echo ">>> Error: could not process stylesheet "$STYLESHEETP"! Aborting."
1.37 + exit 5
1.38 + else
1.39 + if [ -n $VYMPATH ] ; then
1.40 + if [ -n "$WIKISTYLEP" ] ; then
1.41 + mkdir -p $VYMPATH/images
1.42 + cp `dirname $STYLESHEETP`/wiki/* $VYMPATH/images
1.43 + if [ $? -gt 0 ] ; then
1.44 + echo ">>> Warning: could not copy images for WIKI style
1.45 + \""$STYLESHEETP"/wiki/*\"!"
1.46 + else
1.47 + echo ">> WIKI style images \""$STYLESHEETP"/wiki/*\" copied ..."
1.48 + fi
1.49 + fi
1.50 + cp `dirname $STYLESHEETP`/$CSSFILE $VYMPATH
1.51 + if [ $? -gt 0 ] ; then
1.52 + echo ">>> Warning: could not copy CSS-file \""$CSSFILE"\"!"
1.53 + else
1.54 + echo ">> CSS-file \""$CSSFILE"\" copied ..."
1.55 + fi
1.56 + fi
1.57 + fi
1.58 +
1.59 + echo ">> Starting XSLT transformation ..."
1.60 +
1.61 + OPTIONS=" -o $VYMFILE.html \
1.62 + --stringparam filenamep \"$VYMFILE\" \
1.63 + --stringparam wikistylep \"$WIKISTYLEP\" \
1.64 + --stringparam genimagep \"$GENIMAGEP\" \
1.65 + --stringparam imageonlyp \"$IMAGEONLYP\" \
1.66 + --stringparam urlHeadingp \"$URLHEADING\" \
1.67 + --stringparam urlImagep \"$URLIMG\" \
1.68 + --stringparam stylesheetp $CSSFILE \
1.69 + `dirname $STYLESHEETP`/vym2html.xsl \
1.70 + $VYMFILE.xml "
1.71 +
1.72 +
1.73 +# echo Executing: xsltproc $OPTIONS 2>&1
1.74 +# xsltproc $OPTIONS 2>&1
1.75 +
1.76 +xsltproc -o $VYMPATH/$VYMNAME".html" --stringparam filenamep "$VYMPATH/$VYMNAME" --stringparam wikistylep "$WIKISTYLEP" --stringparam genimagep "$GENIMAGEP" --stringparam imageonlyp "$IMAGEONLYP" --stringparam urlHeadingp "$URLHEADING" --stringparam urlImagep "$URLIMAGE" --stringparam stylesheetp "$CSSFILE" `dirname $STYLESHEETP`/vym2html.xsl $VYMPATH/$VYMNAME".xml" 2>&1
1.77 +
1.78 + if [ $? -gt 0 ] ; then
1.79 + echo ">>> Error in xsltproc! Aborting."
1.80 + exit 3
1.81 + fi
1.82 +
1.83 +}
1.84 +
1.85 +
1.86 +txt2html()
1.87 +# change all txt-files into xml-format
1.88 +{
1.89 + for i in `ls $VYMPATH/notes/$VYMNAME-note-*.txt 2>/dev/null`
1.90 + do
1.91 + # Check whether already modified
1.92 + grep "<note>" $i 1>/dev/null
1.93 +
1.94 + if [ $? -gt 0 ] ; then
1.95 + echo ">> Modifying: "$i
1.96 + cp $i $i"_tmp"
1.97 + echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" > $i
1.98 + echo "<note>" >> $i
1.99 + if [ -z "$WIKISTYLEP" ] ; then
1.100 + echo "<![CDATA[" >> $i
1.101 + fi
1.102 +
1.103 + cat $i"_tmp" >> $i
1.104 +
1.105 + if [ -z "$WIKISTYLEP" ] ; then
1.106 + echo "]]>" >> $i
1.107 + fi
1.108 + echo "</note>" >> $i
1.109 +
1.110 + rm $i"_tmp"
1.111 + fi
1.112 + done
1.113 +}
1.114 +
1.115 +
1.116 +remove_files()
1.117 +# remove all temporary unpacked vym-files
1.118 +{
1.119 + echo $VYMFILE_EXT | grep -F ".vym" 1>/dev/null
1.120 +
1.121 + if [ $? = 0 ] ; then
1.122 + echo ">> Removing temporary files ..."
1.123 + for i in `ls $VYMPATH/notes/$VYMNAME-note-*.txt 2>/dev/null`
1.124 + do
1.125 + rm $i
1.126 + done
1.127 +
1.128 + for i in `ls $VYMPATH/images/$VYMNAME-image-*.* 2>/dev/null`
1.129 + do
1.130 + rm $i
1.131 + done
1.132 +
1.133 + rm $VYMPATH/$VYMFILE".xml" 2>/dev/null
1.134 + fi
1.135 +}
1.136 +
1.137 +
1.138 +reducesize()
1.139 +{
1.140 + # optional: reducing image-size
1.141 + echo ">> reducing image size to 256 colors ..."
1.142 + convert -colors 255 $VYMPATH/images/$VYMFILE".png" $VYMPATH/images/$VYMFILE".png"
1.143 +}
1.144 +
1.145 +
1.146 +# -------------------- Parameter check -----------------------
1.147 +GENIMAGEP=""
1.148 +IMAGEONLYP=""
1.149 +WIKISTYLEP=""
1.150 +STYLESHEETP=""
1.151 +CSSFILE="vym.css"
1.152 +
1.153 +USAGE="USAGE:\t`basename $0` vymfile.[vym|xml] -sp=\077 [Options]\n
1.154 +\t-sp=\077: absolute stylesheet path (including name of stylesheet)\n
1.155 +Output:\tvymfile.html\n\n
1.156 +Options:\n
1.157 +-image: creates a clickable image at the beginning of the HTML-output\n
1.158 +-imageonly: creates a clickable image without further HTML-output\n
1.159 +-URLHeading: if set, URLs will show the heading\n
1.160 +-URLImage: if set, URLs will show the globe visible in the map\n
1.161 +-css=\077: tell vym2html to use this CSS-file, default is '$CSSFILE'\n
1.162 +-v: prints the version of vym2html\n
1.163 +-wikistyle: activates some wiki-shortcuts\n
1.164 +\tWiki-style notation overview: \n
1.165 +\tLines:\n
1.166 +\t+ Big headlines start with the '+' character.\n
1.167 +\t- Small headlines start with the '-' character.\n
1.168 +\t Normal text doesn't have any starting notation.\n
1.169 +\t! Notes start with an exclamation.\n
1.170 +\t. Indented text starts with a dot.\n
1.171 +\t\077 Questions start with a question-mark, and\n
1.172 +\t= Answers starts with the equal-sign.\n
1.173 +\t\052 Points for a item-list\n
1.174 +\t# clues\n
1.175 +\n
1.176 +\tLinks:\n
1.177 +\tuse '{...}' or '{(Clemens homepage) http://www.clemens-kraus.de/}'\n\tfor external links.\n
1.178 +\n
1.179 +\tMarkup:\n
1.180 +\t|This is bold| text, while |/this text is italic|, \n\t|*this is pre-formatted|, and |!this is a note|"
1.181 +
1.182 +if [ "$1" = '-v' ]; then
1.183 + echo "vym2html Version: "$VERSION
1.184 + exit 0
1.185 +fi
1.186 +
1.187 +
1.188 +if [ $# -lt 2 ]; then
1.189 + echo -e $USAGE
1.190 + exit 1
1.191 +else
1.192 + VYMFILE_EXT=$1
1.193 + VYMNAME=`echo $VYMFILE_EXT | sed "s/.*\///" | sed "s/\\..*$//"`
1.194 + VYMPATH=`dirname $VYMFILE_EXT`
1.195 +fi
1.196 +
1.197 +shift 1
1.198 +
1.199 +for arg do
1.200 + if [ "$arg" = '-wikistyle' ]; then
1.201 + WIKISTYLEP="yes"
1.202 + elif [ "$arg" = '-image' ]; then
1.203 + GENIMAGEP="yes"
1.204 + elif [ "$arg" = '-imageonly' ]; then
1.205 + IMAGEONLYP="yes"
1.206 + GENIMAGEP="yes"
1.207 + elif [ ${arg:0:3} = '-sp' ]; then # take first 3 chars
1.208 + STYLESHEETP=`echo $arg | cut -d= -f2`
1.209 + elif [ ${arg:0:4} = '-css' ]; then # take first 4 chars
1.210 + CSSFILE=`echo $arg | cut -d= -f2`
1.211 + elif [ $arg = "-useURLHeading" ]; then
1.212 + URLHEADING="yes"
1.213 + elif [ $arg = "-useURLImage" ]; then
1.214 + URLIMAGE="yes"
1.215 + elif [ "$arg" = '-help' ]; then
1.216 + echo -e $USAGE
1.217 + exit 1
1.218 + else
1.219 + echo -e $USAGE
1.220 + exit 1
1.221 + fi
1.222 +done
1.223 +
1.224 +#Debugging
1.225 +echo VYMFILE_EXT=$VYMFILE_EXT
1.226 +echo VYMNAME=$VYMNAME
1.227 +echo VYMPATH=$VYMPATH
1.228 +#echo WIKISTYLEP=$WIKISTYLEP
1.229 +
1.230 +
1.231 +# ---------------------- Los geht's --------------------------
1.232 +echo ">> Processing file '$VYMFILE_EXT' ..."
1.233 +
1.234 +# Unpack vym-file
1.235 +unpacker
1.236 +
1.237 +# Modify "*-note-x.txt" files
1.238 +txt2html
1.239 +
1.240 +# Transform
1.241 +transform
1.242 +
1.243 +#reducesize
1.244 +
1.245 +# clean up
1.246 +remove_files
1.247 +
1.248 +echo ">> Ready!"
1.249 +echo ">> ---------------------"
1.250 +
1.251 +exit 0
1.252 +
1.253 +