insilmaril@36: #!/bin/sh insilmaril@36: # insilmaril@36: # vym2html.sh insilmaril@36: # insilmaril@36: VERSION="0.7" insilmaril@36: # Date: 20040625 insilmaril@36: # Author: Clemens Kraus (http://www.clemens-kraus.de) insilmaril@36: # insilmaril@36: # AddOns: Uwe Drechsel insilmaril@36: #echo $@ insilmaril@36: insilmaril@36: insilmaril@36: unpacker() insilmaril@36: # Unpack vym-file, only if it is one insilmaril@36: { insilmaril@36: echo $VYMFILE_EXT | grep -F ".vym" 1>/dev/null insilmaril@36: insilmaril@36: if [ $? = 0 ] ; then insilmaril@36: echo ">> Unpacking files ..." insilmaril@36: unzip $VYMFILE_EXT -d $VYMPATH 1>/dev/null insilmaril@36: if [ $? -gt 0 ] ; then insilmaril@36: echo ">>> Error in unzip! Aborting." insilmaril@36: exit 4 insilmaril@36: fi insilmaril@36: fi insilmaril@36: } insilmaril@36: insilmaril@36: insilmaril@36: transform() insilmaril@36: { insilmaril@36: # copy stylesheet insilmaril@36: if [ -z $STYLESHEETP ] ; then insilmaril@36: echo ">>> Error: could not process stylesheet "$STYLESHEETP"! Aborting." insilmaril@36: exit 5 insilmaril@36: else insilmaril@36: if [ -n $VYMPATH ] ; then insilmaril@36: if [ -n "$WIKISTYLEP" ] ; then insilmaril@36: mkdir -p $VYMPATH/images insilmaril@36: cp `dirname $STYLESHEETP`/wiki/* $VYMPATH/images insilmaril@36: if [ $? -gt 0 ] ; then insilmaril@36: echo ">>> Warning: could not copy images for WIKI style insilmaril@36: \""$STYLESHEETP"/wiki/*\"!" insilmaril@36: else insilmaril@36: echo ">> WIKI style images \""$STYLESHEETP"/wiki/*\" copied ..." insilmaril@36: fi insilmaril@36: fi insilmaril@36: cp `dirname $STYLESHEETP`/$CSSFILE $VYMPATH insilmaril@36: if [ $? -gt 0 ] ; then insilmaril@36: echo ">>> Warning: could not copy CSS-file \""$CSSFILE"\"!" insilmaril@36: else insilmaril@36: echo ">> CSS-file \""$CSSFILE"\" copied ..." insilmaril@36: fi insilmaril@36: fi insilmaril@36: fi insilmaril@36: insilmaril@36: echo ">> Starting XSLT transformation ..." insilmaril@36: insilmaril@36: OPTIONS=" -o $VYMFILE.html \ insilmaril@36: --stringparam filenamep \"$VYMFILE\" \ insilmaril@36: --stringparam wikistylep \"$WIKISTYLEP\" \ insilmaril@36: --stringparam genimagep \"$GENIMAGEP\" \ insilmaril@36: --stringparam imageonlyp \"$IMAGEONLYP\" \ insilmaril@36: --stringparam urlHeadingp \"$URLHEADING\" \ insilmaril@36: --stringparam urlImagep \"$URLIMG\" \ insilmaril@36: --stringparam stylesheetp $CSSFILE \ insilmaril@36: `dirname $STYLESHEETP`/vym2html.xsl \ insilmaril@36: $VYMFILE.xml " insilmaril@36: insilmaril@36: insilmaril@36: # echo Executing: xsltproc $OPTIONS 2>&1 insilmaril@36: # xsltproc $OPTIONS 2>&1 insilmaril@36: insilmaril@36: 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 insilmaril@36: insilmaril@36: if [ $? -gt 0 ] ; then insilmaril@36: echo ">>> Error in xsltproc! Aborting." insilmaril@36: exit 3 insilmaril@36: fi insilmaril@36: insilmaril@36: } insilmaril@36: insilmaril@36: insilmaril@36: txt2html() insilmaril@36: # change all txt-files into xml-format insilmaril@36: { insilmaril@36: for i in `ls $VYMPATH/notes/$VYMNAME-note-*.txt 2>/dev/null` insilmaril@36: do insilmaril@36: # Check whether already modified insilmaril@36: grep "" $i 1>/dev/null insilmaril@36: insilmaril@36: if [ $? -gt 0 ] ; then insilmaril@36: echo ">> Modifying: "$i insilmaril@36: cp $i $i"_tmp" insilmaril@36: echo "" > $i insilmaril@36: echo "" >> $i insilmaril@36: if [ -z "$WIKISTYLEP" ] ; then insilmaril@36: echo "> $i insilmaril@36: fi insilmaril@36: insilmaril@36: cat $i"_tmp" >> $i insilmaril@36: insilmaril@36: if [ -z "$WIKISTYLEP" ] ; then insilmaril@36: echo "]]>" >> $i insilmaril@36: fi insilmaril@36: echo "" >> $i insilmaril@36: insilmaril@36: rm $i"_tmp" insilmaril@36: fi insilmaril@36: done insilmaril@36: } insilmaril@36: insilmaril@36: insilmaril@36: remove_files() insilmaril@36: # remove all temporary unpacked vym-files insilmaril@36: { insilmaril@36: echo $VYMFILE_EXT | grep -F ".vym" 1>/dev/null insilmaril@36: insilmaril@36: if [ $? = 0 ] ; then insilmaril@36: echo ">> Removing temporary files ..." insilmaril@36: for i in `ls $VYMPATH/notes/$VYMNAME-note-*.txt 2>/dev/null` insilmaril@36: do insilmaril@36: rm $i insilmaril@36: done insilmaril@36: insilmaril@36: for i in `ls $VYMPATH/images/$VYMNAME-image-*.* 2>/dev/null` insilmaril@36: do insilmaril@36: rm $i insilmaril@36: done insilmaril@36: insilmaril@36: rm $VYMPATH/$VYMFILE".xml" 2>/dev/null insilmaril@36: fi insilmaril@36: } insilmaril@36: insilmaril@36: insilmaril@36: reducesize() insilmaril@36: { insilmaril@36: # optional: reducing image-size insilmaril@36: echo ">> reducing image size to 256 colors ..." insilmaril@36: convert -colors 255 $VYMPATH/images/$VYMFILE".png" $VYMPATH/images/$VYMFILE".png" insilmaril@36: } insilmaril@36: insilmaril@36: insilmaril@36: # -------------------- Parameter check ----------------------- insilmaril@36: GENIMAGEP="" insilmaril@36: IMAGEONLYP="" insilmaril@36: WIKISTYLEP="" insilmaril@36: STYLESHEETP="" insilmaril@36: CSSFILE="vym.css" insilmaril@36: insilmaril@36: USAGE="USAGE:\t`basename $0` vymfile.[vym|xml] -sp=\077 [Options]\n insilmaril@36: \t-sp=\077: absolute stylesheet path (including name of stylesheet)\n insilmaril@36: Output:\tvymfile.html\n\n insilmaril@36: Options:\n insilmaril@36: -image: creates a clickable image at the beginning of the HTML-output\n insilmaril@36: -imageonly: creates a clickable image without further HTML-output\n insilmaril@36: -URLHeading: if set, URLs will show the heading\n insilmaril@36: -URLImage: if set, URLs will show the globe visible in the map\n insilmaril@36: -css=\077: tell vym2html to use this CSS-file, default is '$CSSFILE'\n insilmaril@36: -v: prints the version of vym2html\n insilmaril@36: -wikistyle: activates some wiki-shortcuts\n insilmaril@36: \tWiki-style notation overview: \n insilmaril@36: \tLines:\n insilmaril@36: \t+ Big headlines start with the '+' character.\n insilmaril@36: \t- Small headlines start with the '-' character.\n insilmaril@36: \t Normal text doesn't have any starting notation.\n insilmaril@36: \t! Notes start with an exclamation.\n insilmaril@36: \t. Indented text starts with a dot.\n insilmaril@36: \t\077 Questions start with a question-mark, and\n insilmaril@36: \t= Answers starts with the equal-sign.\n insilmaril@36: \t\052 Points for a item-list\n insilmaril@36: \t# clues\n insilmaril@36: \n insilmaril@36: \tLinks:\n insilmaril@36: \tuse '{...}' or '{(Clemens homepage) http://www.clemens-kraus.de/}'\n\tfor external links.\n insilmaril@36: \n insilmaril@36: \tMarkup:\n insilmaril@36: \t|This is bold| text, while |/this text is italic|, \n\t|*this is pre-formatted|, and |!this is a note|" insilmaril@36: insilmaril@36: if [ "$1" = '-v' ]; then insilmaril@36: echo "vym2html Version: "$VERSION insilmaril@36: exit 0 insilmaril@36: fi insilmaril@36: insilmaril@36: insilmaril@36: if [ $# -lt 2 ]; then insilmaril@36: echo -e $USAGE insilmaril@36: exit 1 insilmaril@36: else insilmaril@36: VYMFILE_EXT=$1 insilmaril@36: VYMNAME=`echo $VYMFILE_EXT | sed "s/.*\///" | sed "s/\\..*$//"` insilmaril@36: VYMPATH=`dirname $VYMFILE_EXT` insilmaril@36: fi insilmaril@36: insilmaril@36: shift 1 insilmaril@36: insilmaril@36: for arg do insilmaril@36: if [ "$arg" = '-wikistyle' ]; then insilmaril@36: WIKISTYLEP="yes" insilmaril@36: elif [ "$arg" = '-image' ]; then insilmaril@36: GENIMAGEP="yes" insilmaril@36: elif [ "$arg" = '-imageonly' ]; then insilmaril@36: IMAGEONLYP="yes" insilmaril@36: GENIMAGEP="yes" insilmaril@36: elif [ ${arg:0:3} = '-sp' ]; then # take first 3 chars insilmaril@36: STYLESHEETP=`echo $arg | cut -d= -f2` insilmaril@36: elif [ ${arg:0:4} = '-css' ]; then # take first 4 chars insilmaril@36: CSSFILE=`echo $arg | cut -d= -f2` insilmaril@36: elif [ $arg = "-useURLHeading" ]; then insilmaril@36: URLHEADING="yes" insilmaril@36: elif [ $arg = "-useURLImage" ]; then insilmaril@36: URLIMAGE="yes" insilmaril@36: elif [ "$arg" = '-help' ]; then insilmaril@36: echo -e $USAGE insilmaril@36: exit 1 insilmaril@36: else insilmaril@36: echo -e $USAGE insilmaril@36: exit 1 insilmaril@36: fi insilmaril@36: done insilmaril@36: insilmaril@36: #Debugging insilmaril@36: echo VYMFILE_EXT=$VYMFILE_EXT insilmaril@36: echo VYMNAME=$VYMNAME insilmaril@36: echo VYMPATH=$VYMPATH insilmaril@36: #echo WIKISTYLEP=$WIKISTYLEP insilmaril@36: insilmaril@36: insilmaril@36: # ---------------------- Los geht's -------------------------- insilmaril@36: echo ">> Processing file '$VYMFILE_EXT' ..." insilmaril@36: insilmaril@36: # Unpack vym-file insilmaril@36: unpacker insilmaril@36: insilmaril@36: # Modify "*-note-x.txt" files insilmaril@36: txt2html insilmaril@36: insilmaril@36: # Transform insilmaril@36: transform insilmaril@36: insilmaril@36: #reducesize insilmaril@36: insilmaril@36: # clean up insilmaril@36: remove_files insilmaril@36: insilmaril@36: echo ">> Ready!" insilmaril@36: echo ">> ---------------------" insilmaril@36: insilmaril@36: exit 0 insilmaril@36: insilmaril@36: