Update: I've added a perl
method, using module HTML::FromANSI from CPAN .. To install it, just extract it to a directory, and run, as root: perl -MCPAN -e 'install HTML::FromANSI'
from that directory. The particular feature to suit your request is a script called ansi2html
. Interestingly enough, it shows the same loss-of-color after the overlaid k
in the filenames, as does the elisp-shell script... Here is an example usage:
ls -l --color=always /bin/*k* |
grep --color=always "k\|x\|2010" |
ansi2html >/tmp/example.html
firefox /tmp/example.html
Here is the html output. as seen in Firefox:
Here is a method using an emacs elisp-shell script... for the example, called htmlize ...Emacs does not need to be running.
I originally tested it on a black background, but I noticed that for some reason, a white background doesn't play well with one of the introduced Escape Codes,\e[K
, which seems to be ERASE_LINE (Erase the current line of terminal output). I've added a line to remove this Escape Code. It now works for a white background.
Here is an example of color highlighted output from ls
being piped to grep
for further color highlighting.
ls -l --color=always /bin/*k* |
grep --color=always "k\|x\|2010" >/tmp/example
htmlize /tmp/example
firefox /tmp/example.html
this is the elsip-shell
script.
#!/bin/sh
":"; exec /usr/bin/emacs -Q --script "$0" -- "$@" # -*-emacs-lisp-*-
(require 'ansi-color) (require 'htmlize)
(find-file (setq path-in (cadr argv)))
(ansi-color-apply-on-region (point-min) (point-max))
(switch-to-buffer (buffer-name (htmlize-buffer)))
(write-file (concat path-in ".html"))
Here is a sample of the html output, in Firefox... If I get time, I'll look further into the overlaying ANSI codes issue. where the red k
s overlap the green filenames, but that is only there because of a hurriedly chosen test regex for grep... (maybe that is something \e[K
influences...
