Converting ANSI escape sequence to html
By katsumii on Nov 27, 2007
If you are a type of blogger who often copy&paste text data from terminal, you may have wished that you want to preserve color, highlight, inversion, flashing, etc which are provided by ANSI escape sequence when copying to <pre></pre> block. Today, I found ANSIfilter. So, I gave it a try.
Unfortunately, I haven't seen much color on my Solaris terminal. I couldn't find vim installed, either. So, I tested this on Windows Cygwin environment.
Here's the screenshot of what I did to capture all the output.
Here's what I did to convert terminal output capture(a file named 'typescript') to html.
$ cat typescript | ansifilter -H > af.out.html
Now, look in the resultant af.out.html file.
$ grep -nw pre af.out.html
8:<pre style="font-family: Courier New; font-size: 10pt;">Script started on Tue Nov 27 16:30:07 2007
Lines between 8 and 34 is <pre> section. Now, I copy&paste these 27 lines in this blog entry.
Script started on Tue Nov 27 16:30:07 2007
$ alias ls='ls -trA --show-control-chars --color=auto'
$ ls ../To_Archive/misc/ansifilter/
COPYING .easiboxrc makefile INSTALL ChangeLog README ansifilter-gui.exe ansifilter.exe man src
$ vim --cmd "syntax on" foobar.html
l" 9 lines, 260 characters<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<link rel="search" type="application/opensearchdescription+xml" title="whatever search" href="http://127.0.0.1/foobar.xmm>
This is a ansifilter test.
Script done on Tue Nov 27 16:30:41 2007
So, the html output looks acceptably similar to the actual screen capture. Yes, I customized my CSS but I think that would be an easy task for who is still reading this entry.
I regret that I overly complicated this test by using 'vim'. After all, I didn't expect ANSIfilter can create clean output from curses heavy program like vim,lynx,links,w3m.