if [ -x /usr/bin/w3m ]
then
  CONVERT=/usr/bin/w3m
  ARGS="-T text/html -dump"
elif [ -x /usr/bin/lynx ]
then
  CONVERT=/usr/bin/lynx
  ARGS="-force_html -dump -nolist -width=72"
elif [ -x /usr/bin/links ]
then
  CONVERT=/usr/bin/links
  ARGS="-dump"
else
  echo >&2 "No way to convert HTML to text found."
  exit 1
fi

case "$1" in
stylesheet)
  if [ "$VERBOSE" -ge 1 ]
  then
    echo >&2 "Convert to HTML (no chunks)"
  fi
  echo "http://docbook.sourceforge.net/release/xsl/current/html/docbook.xsl"
  ;;
post-process)
  if [ "$VERBOSE" -ge 1 ]
  then
    echo >&2 "Convert HTML to ASCII"
  fi
  ${CONVERT} ${ARGS} ${POSTARGS} ${XSLT_PROCESSED} > \
   "$OUTPUT_DIR/$(basename ${XSLT_PROCESSED%.*}).txt"
  ;;
esac
