The problem: Quickly converting an ASCII file with color escapes to html via the cli or bash scripts.
Initially, ansi2html was the solution and, while it is really well done, a fixed-width/mono-spaced font was needed so things like logs, tables or reports would line up. Unfortunately, most browsers render html with a variable-width font by default and ansi2html has no obvious way to change that.
Fortunately, Vim comes bundled with a plug-in, 2html.vim, (See the TOhtml command) which uses <PRE>. When combined with AnsiEsc - another plug-in that is not bundled with Vim - and a tiny bash script, it solves the problem nicely.
This will overwrite files without warning, use at your own risk!
Installation
- Install AnsiEsc
- Copy these to a directory in your PATH. e.g. ~/bin, $HOME/bin, etc..
Usage:
-
vansi2html - Converting ANSI with color escapes:
$ vanis2html foo.txt Created foo.txt.html -
vsyntax2html - Save Vim's syntax highlighted output to html:
$ vsyntax2html foo.java Created foo.java.html