Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Html to ansi colored terminal text

I am under Linux and I want to fetch an html page from the web and then output it on terminal. I found out that html2text essentially does the job, but it converts my html to a plain text whereas I would better convert it into ansi colored text in the spirit of ls --color=auto. Any ideas?

like image 802
Sergey Avatar asked Mar 24 '11 09:03

Sergey


1 Answers

The elinks browser can do that. Other text browsers such as lynx or w3m might be able to do that as well.

elinks -dump -dump-color-mode 1 http://example.com/ 

the above example provides a text version of http://example.com/ using 16 colors. The output format can be customized further depending on need.

The -dump option enables the dump mode, which just prints the whole page as text, with the link destinations printed out in a kind of "email-style".

-dump-color-mode 1 enables the coloring of the output using the 16 basic terminal colors. Depending on the value and the capabilities of the terminal emulator this can be up to ~16 million (True Color). The values are documented in elinks.conf(5).

The colors used for output can be configured as well, which is documented in elinks.conf(5) as well.

like image 52
davrieb Avatar answered Oct 02 '22 19:10

davrieb