Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to write notes (in HTML format) when learning linux. When I need to note colorful terminal text output, I want the color of terminal text can be remained in my notes, eg:

Note 1: Test

The output of xx command is

<pre>
[root@webserver ~]# ll /
total 100
drwxrwxrwt.   7 root root  4096 8月  24 12:22 <span style='background-color:green; color:blue;'>tmp</span>
drwxr-xr-x.  14 root root  4096 7月  19 21:20 <span style='color:blue;'>usr</span>
</pre>

I can manually add HTML code wrapper around the plain text, but I hope there's an automatical way to achieve that.

Currently, I'm using putty on Windows to connnect to remote CentOS linux server.

share|improve this question
    
you want to copy data from terminal to buffer and when you paste it in notepad you expected to seen html near color words? – Ishikawa Yoshi Aug 24 '12 at 7:35
    
yes, that's what i wanted. i think this can be done in terminal emulator software (translate control characters into HTML), but i don't know if there's such emulator has such function. – LiuYan 刘研 Aug 24 '12 at 7:41
2  
    
thanks for the link, i didn't notice that option before. however that's a slight different question, i want the paste to be HTML code, not rich text format (and my RTF paste seems malformed characters). – LiuYan 刘研 Aug 24 '12 at 8:27
1  
stackoverflow.com/questions/2033268/linux-shell-output-to-html maybe this link also helps you – Ishikawa Yoshi Aug 24 '12 at 8:38

Use the script utility to capture the terminal output to a file (ansi color control characters included) and then convert it to html with ansi2html script. Eg:

inigo:tmp> script
Script started, file is typescript
inigo:tmp> ls
#
# lots of colour output
# 
inigo:tmp> exit
exit
Script done, file is typescript
inigo:tmp> cat typescript  | ansi2html.sh > typescript.html

If using PuTTY, "All session output" login option will also keep the ansi color codes.

share|improve this answer
    
Awesome, made my day! Thanks! – georg Nov 12 '14 at 12:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .