scripts/vym2html.sh
author insilmaril
Tue Jul 17 11:19:50 2007 +0000 (2007-07-17)
changeset 550 55236fe5a630
permissions -rwxr-xr-x
1.9.2 Bugfixes for exports
     1 #!/bin/sh
     2 #
     3 # vym2html.sh
     4 #
     5 VERSION="0.7"
     6 # Date: 20040625
     7 # Author: Clemens Kraus (http://www.clemens-kraus.de)
     8 #
     9 # AddOns: Uwe Drechsel
    10 #echo $@
    11 
    12 
    13 unpacker()
    14 # Unpack vym-file, only if it is one
    15 {
    16   echo $VYMFILE_EXT | grep -F ".vym" 1>/dev/null
    17 
    18   if [ $? = 0 ] ; then
    19 	  echo ">> Unpacking files ..."
    20 	  unzip $VYMFILE_EXT -d $VYMPATH 1>/dev/null
    21 	  if [ $? -gt 0 ] ; then
    22 		echo ">>> Error in unzip! Aborting."
    23 	  	exit 4
    24 	  fi
    25   fi
    26 }
    27 
    28 
    29 transform()
    30 {
    31   # copy stylesheet
    32   if [ -z $STYLESHEETP ] ; then
    33 	  echo ">>> Error: could not process stylesheet "$STYLESHEETP"! Aborting."
    34 	  exit 5
    35   else
    36 	  if [ -n $VYMPATH ] ; then
    37 		  if [ -n "$WIKISTYLEP" ] ; then
    38 		    mkdir -p $VYMPATH/images
    39 			cp `dirname $STYLESHEETP`/wiki/* $VYMPATH/images
    40 			if [ $? -gt 0 ] ; then
    41 				echo ">>> Warning: could not copy images for WIKI style
    42 				\""$STYLESHEETP"/wiki/*\"!"
    43 			else
    44 			  echo ">> WIKI style images \""$STYLESHEETP"/wiki/*\" copied ..."
    45 			fi  
    46 		  fi
    47 	  	cp `dirname $STYLESHEETP`/$CSSFILE $VYMPATH
    48 		if [ $? -gt 0 ] ; then
    49 			echo ">>> Warning: could not copy CSS-file \""$CSSFILE"\"!"
    50 		else
    51 		  echo ">> CSS-file \""$CSSFILE"\" copied ..."
    52 		fi
    53 	  fi
    54   fi
    55   
    56   echo ">> Starting XSLT transformation ..."
    57 
    58   OPTIONS=" -o $VYMFILE.html \
    59   --stringparam filenamep \"$VYMFILE\" \
    60   --stringparam wikistylep \"$WIKISTYLEP\" \
    61   --stringparam genimagep \"$GENIMAGEP\" \
    62   --stringparam imageonlyp \"$IMAGEONLYP\" \
    63   --stringparam urlHeadingp \"$URLHEADING\" \
    64   --stringparam urlImagep \"$URLIMG\" \
    65   --stringparam stylesheetp $CSSFILE  \
    66   `dirname $STYLESHEETP`/vym2html.xsl \
    67   $VYMFILE.xml "
    68   
    69   
    70 # echo Executing: xsltproc $OPTIONS 2>&1
    71 #  xsltproc $OPTIONS 2>&1
    72 
    73 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
    74 
    75   if [ $? -gt 0 ] ; then
    76 	  echo ">>> Error in xsltproc! Aborting."
    77 	  exit 3
    78   fi
    79   
    80 }
    81 
    82 
    83 txt2html()
    84 # change all txt-files into xml-format
    85 {
    86   for i in `ls $VYMPATH/notes/$VYMNAME-note-*.txt 2>/dev/null`
    87   do
    88     # Check whether already modified
    89 	grep "<note>" $i 1>/dev/null
    90 	
    91 	if [ $? -gt 0 ] ; then
    92 	  echo ">> Modifying: "$i
    93 	  cp $i $i"_tmp"
    94 	  echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" > $i
    95 	  echo "<note>" >> $i
    96 	  if [ -z "$WIKISTYLEP" ] ; then
    97 		  echo "<![CDATA[" >> $i
    98 	  fi
    99 	  
   100 	  cat $i"_tmp" >> $i
   101   
   102 	  if [ -z "$WIKISTYLEP" ] ; then
   103 		  echo "]]>" >> $i
   104 	  fi
   105 	  echo "</note>" >> $i
   106   
   107 	  rm $i"_tmp"
   108 	fi
   109   done
   110 }
   111 
   112 
   113 remove_files()
   114 # remove all temporary unpacked vym-files
   115 {
   116   echo $VYMFILE_EXT | grep -F ".vym" 1>/dev/null
   117 	
   118   if [ $? = 0 ] ; then
   119 	echo ">> Removing temporary files ..."
   120 	for i in `ls $VYMPATH/notes/$VYMNAME-note-*.txt 2>/dev/null`
   121 	do
   122 	  rm $i
   123 	done
   124   
   125 	for i in `ls $VYMPATH/images/$VYMNAME-image-*.* 2>/dev/null`
   126 	do
   127 	  rm $i
   128 	done
   129   
   130 	rm $VYMPATH/$VYMFILE".xml" 2>/dev/null
   131   fi
   132 }
   133 
   134 
   135 reducesize()
   136 {
   137   # optional: reducing image-size
   138   echo ">> reducing image size to 256 colors ..."
   139   convert -colors 255 $VYMPATH/images/$VYMFILE".png" $VYMPATH/images/$VYMFILE".png"
   140 }
   141 
   142 
   143 # -------------------- Parameter check -----------------------
   144 GENIMAGEP=""
   145 IMAGEONLYP=""
   146 WIKISTYLEP=""
   147 STYLESHEETP=""
   148 CSSFILE="vym.css"
   149 
   150 USAGE="USAGE:\t`basename $0`  vymfile.[vym|xml]  -sp=\077  [Options]\n
   151 \t-sp=\077: absolute stylesheet path (including name of stylesheet)\n
   152 Output:\tvymfile.html\n\n
   153 Options:\n
   154 -image: creates a clickable image at the beginning of the HTML-output\n
   155 -imageonly: creates a clickable image without further HTML-output\n
   156 -URLHeading: if set, URLs will show the heading\n
   157 -URLImage: if set, URLs will show the globe visible in the map\n
   158 -css=\077: tell vym2html to use this CSS-file, default is '$CSSFILE'\n
   159 -v: prints the version of vym2html\n
   160 -wikistyle: activates some wiki-shortcuts\n
   161 \tWiki-style notation overview: \n
   162 \tLines:\n
   163 \t+ Big headlines start with the '+' character.\n
   164 \t- Small headlines start with the '-' character.\n
   165 \t  Normal text doesn't have any starting notation.\n
   166 \t! Notes start with an exclamation.\n
   167 \t. Indented text starts with a dot.\n
   168 \t\077 Questions start with a question-mark, and\n
   169 \t= Answers starts with the equal-sign.\n
   170 \t\052 Points for a item-list\n
   171 \t# clues\n
   172 \n
   173 \tLinks:\n
   174 \tuse '{...}' or '{(Clemens homepage) http://www.clemens-kraus.de/}'\n\tfor external links.\n
   175 \n
   176 \tMarkup:\n
   177 \t|This is bold| text, while |/this text is italic|, \n\t|*this is pre-formatted|, and |!this is a note|"
   178 
   179 if [ "$1" = '-v' ]; then
   180 	  echo "vym2html Version: "$VERSION
   181 	  exit 0
   182 fi
   183 
   184 
   185 if [ $# -lt 2  ]; then 
   186 	echo -e $USAGE
   187 	exit 1
   188 else
   189 	VYMFILE_EXT=$1
   190 	VYMNAME=`echo $VYMFILE_EXT | sed "s/.*\///" | sed "s/\\..*$//"`
   191 	VYMPATH=`dirname $VYMFILE_EXT`
   192 fi
   193 
   194 shift 1
   195 
   196 for arg do
   197   if [ "$arg" = '-wikistyle' ]; then
   198 	  WIKISTYLEP="yes"
   199   elif [ "$arg" = '-image' ]; then
   200 	  GENIMAGEP="yes"
   201   elif [ "$arg" = '-imageonly' ]; then
   202 	  IMAGEONLYP="yes"
   203 	  GENIMAGEP="yes"
   204   elif [ ${arg:0:3} = '-sp' ]; then			# take first 3 chars
   205 	  STYLESHEETP=`echo $arg | cut -d= -f2`
   206   elif [ ${arg:0:4} = '-css' ]; then		# take first 4 chars
   207 	  CSSFILE=`echo $arg | cut -d= -f2`
   208   elif [ $arg = "-useURLHeading" ]; then
   209 		URLHEADING="yes"		
   210   elif [ $arg = "-useURLImage" ]; then
   211 		URLIMAGE="yes"		
   212   elif [ "$arg" = '-help' ]; then
   213 	echo -e $USAGE
   214 	exit 1
   215   else
   216 	echo -e $USAGE
   217 	exit 1
   218   fi
   219 done
   220 
   221 #Debugging
   222 echo VYMFILE_EXT=$VYMFILE_EXT
   223 echo VYMNAME=$VYMNAME
   224 echo VYMPATH=$VYMPATH
   225 #echo WIKISTYLEP=$WIKISTYLEP
   226 
   227 
   228 # ---------------------- Los geht's --------------------------
   229 echo ">> Processing file '$VYMFILE_EXT' ..."
   230 
   231 # Unpack vym-file
   232 unpacker
   233 
   234 # Modify "*-note-x.txt" files
   235 txt2html
   236 
   237 # Transform
   238 transform
   239 
   240 #reducesize
   241 
   242 # clean up
   243 remove_files
   244 
   245 echo ">> Ready!"
   246 echo ">> ---------------------"
   247 
   248 exit 0
   249 
   250