[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
htmlize: Command line interface to http://rtfm.etla.org/emacs/htmlfontif
From: |
Simon Josefsson |
Subject: |
htmlize: Command line interface to http://rtfm.etla.org/emacs/htmlfontify/ |
Date: |
Wed, 14 Jul 2004 16:26:27 +0200 |
User-agent: |
Gnus/5.110003 (No Gnus v0.3) Emacs/21.3.50 (gnu/linux) |
Thanks for all suggestions and comments. I ended up using
htmlfontify.el instead, because I was able to use it in batch mode.
I'm sure 'highlight' is good, but it didn't appear to be able to
fontify things like "compilation-mode" does, which is what I needed.
Below is the latest script. If anyone is interested in future
releases, htmlize is part of <http://josefsson.org/autobuild/>. The
autobuild distribution archive contain a man page and Texinfo
documentation for htmlize too. Hopefully the script won't change much
from now on, so I likely won't post it again here.
#!/bin/sh
# Copyright (C) 2004 Simon Josefsson.
#
# This file is part of Autobuild.
#
# Autobuild is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# Autobuild is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Autobuild; see the file COPYING. If not, write to the
# Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
# MA 02111-1307, USA.
prog="`basename \"$0\"`"
rcs_revision='$Revision: 1.11 $'
rcs_version=`set - $rcs_revision; echo $2`
program=`echo $0 | sed -e 's!.*/!!'`
version="htmlize (autobuild) $rcs_version
Copyright (C) 2004 Simon Josefsson
There is NO warranty. You may redistribute this software
under the terms of the GNU General Public License.
For more information about these matters, see the files named COPYING."
usage="Usage: $prog [OPTION]... INFILE [OUTFILE [EMACS-MODE]]
Launch Emacs and load INFILE into a buffer, then invoke a major mode
for font locking, and render the fontified buffer as HTML, saving the
result into OUTFILE.
Emacs must have htmlfontify.el installed in its load-path.
If OUTFILE is not specified, it will use INFILE appended with .html.
If EMACS-MODE is not specified, compilation-mode will be used.
Options:
--emacs COMMAND Use specified command to invoke emacs, e.g. \"emacs21\".
--mode MODE Fontify file using specified Emacs mode, defaults to
\"compilation-mode\". E.g., \"sh-mode\".
-f, --force Overwrite OUTFILE if it exists, instead of
exiting unsuccessfully with an error message.
-u, --update Only write to OUTFILE when OUTFILE does not exist,
or when INFILE is more recent than OUTFILE.
-h, --help Display this help and exit successfully.
--version Display version information and exit successfully.
Environment variables:
EMACS The Emacs editor command.
Simple example:
$prog mybuildlog.txt mybuildlog.html
Report bugs to <address@hidden>."
while test $# -gt 0; do
case $1 in
-h) echo "$usage"; exit 0;;
--help) echo "$usage"; exit 0;;
--version) echo "$version"; exit 0;;
-f) force=t;;
--force) force=t;;
-u) update=t;;
--update) update=t;;
--emacs) shift; EMACS=$1;;
-*)
echo "$0: Unknown or ambiguous option \`$1'." >&2
echo "$0: Try \`--help' for more information." >&2
exit 1;;
*)
if test -z "$INFILE"; then
INFILE=$1
elif test -z "$OUTFILE"; then
OUTFILE=$1
elif test -z "$EMACSMODE"; then
EMACSMODE=$1
else
echo "$0: Extra non-option argument \`$1'." >&2
exit 1
fi;;
esac
shift
done
if test -z "$INFILE"; then
echo "$usage"
exit 0
fi
OUTFILE=${OUTFILE:-$INFILE.html}
EMACSMODE=${EMACSMODE:-compilation-mode}
EMACS=${EMACS:-emacs}
if test ! -f $INFILE; then
echo "$0: No such file \`$INFILE'." >&2
exit 1
fi
if test -f $OUTFILE; then
if test -n "$force"; then
rm -f $OUTFILE || exit 1
elif test -n "$update"; then
if test $INFILE -nt $OUTFILE; then
rm -f $OUTFILE || exit 1
else
echo "$0: Nothing to be done for \`$OUTFILE'." >&2
exit 0
fi
else
echo "$0: File already exists: \`$OUTFILE'." >&2
exit 1
fi
fi
$EMACS --batch --eval "(let ((debug-on-error t) (font-lock-verbose nil)
(hfy-display-class '((class . color))) (coding-system-for-write 'binary))
(autoload 'htmlfontify-buffer \"htmlfontify\") (find-file \"$INFILE\")
($EMACSMODE) (font-lock-fontify-buffer) (htmlfontify-buffer) (setq
buffer-file-name \"$OUTFILE\") (save-buffer) (kill-emacs))"