linux html css output follow,command line - Converting colored output into html - Unix & Linux Stack...

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:

aSEWU.png

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 ks 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...

vlW2Y.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值