Convert text with ANSI color codes to HTML or to LaTeX.
Inspired by and developed off of the work of pixelbeat and blackjack.
Read the docs for more informations.
from ansi2html import Ansi2HTMLConverter
conv = Ansi2HTMLConverter()
ansi = "".join(sys.stdin.readlines())
html = conv.convert(ansi)$ ls --color=always | ansi2html > directories.html
$ sudo tail /var/log/messages | ccze -A | ansi2html > logs.html
$ task rc._forcecolor:yes limit:0 burndown | ansi2html > burndown.htmlYou can also have ansi2html run a command inside a pseudo‑terminal so it emits colored output, which is then converted to HTML:
$ ansi2html git log -p > git-log.html- Everything after the first non-option token is treated as the command and its arguments.
- To avoid ambiguity with
ansi2htmloptions, you can separate with--:
$ ansi2html --inline -- git log -p > inline-git-log.htmlFor embeddable snippets, use --standalone (or -S) to wrap the converted output in a
<code> element without the full HTML template:
$ echo $'\e[31mRED\e[0m' | ansi2html --standaloneSee the list of full options with:
$ ansi2html --help$ pip3 install ansi2htmlSource: https://github.com/pycontribs/ansi2html/
pypi: https://pypi.org/project/ansi2html/
ansi2html is licensed LGPLv3+.
- Author: Ralph Bean
- Contributor: Robin Schneider