Converting ANSI escape sequence to html

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
34:</pre>

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
p

Administrator@kinow23 /c/e/tmp

$ alias ls='ls -trA --show-control-chars --color=auto'
p

Administrator@kinow23 /c/e/tmp

$ ls ../To_Archive/misc/ansifilter/
COPYING .easiboxrc makefile INSTALL ChangeLog README ansifilter-gui.exe ansifilter.exe man src
p

Administrator@kinow23 /c/e/tmp

$ vim --cmd "syntax on" foobar.html
l" 9 lines, 260 characters<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<
head>
<
link rel="search" type="application/opensearchdescription+xml" title="whatever search" href="http://127.0.0.1/foobar.xmm>
</
head>
<
body>
This is a ansifilter test.
</body>
</
html>
~ p

Administrator@kinow23 /c/e/tmp

$ exit
exit

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.

Comments:

Post a Comment:
  • HTML Syntax: NOT allowed
About

The views expressed on this blog are my own and do not necessarily reflect the views of Oracle.

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today