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