tmux to html
Posted: September 05, 2025
Category:
(none)
For a post about org-mode kombucha I've been exporting my terminal content to html.
With tmux and ascii2html (there are multiple programs with that name, here I refer to
the one part of Debian's colorized-logs
: apt install colorized-logs
), this is a
breeze.
- Resize a given pane to the desired size:
:resize-pane -x 80 -y 24
. - Export its content to html:
:run-shell "tmux capture-pane -e -p | ansi2html"
.
I improved the html export a bit, by removing the headers and footer (as I insert the export on existing web pages), and attempting some best-effort substitution of default colors to use those of my terminal configuration. I ended up with the following tmux configuration entry:
bind-key e run-shell "tmux capture-pane -e -p | ansi2html --no-header --no-wrap | sed -e 's/#aa0/#ebcb8b/g' -e 's/#55f/#81a1c1/g' -e 's/#f55/#bf616a/g' -e 's/#ff5/#ebcb8b/g' -e 's/#5f5/#a3be8c/g' -e 's/#00a/#81a1c1/g' -e 's/#55ffff/#88c0d0/g' -e 's/#0a0/#a3be8c/g' | xclip -i -sel c -f"
Since I'm writing this post currently in a tmux pane, here's what I obtain:
++++++++++++ ++++++ │--- + + + + │title: tmux to html + + + + │icon: 💾 + + + + │--- + + + + │ + + ++++++ │<style> + + │body { + + Shapes: 00013 │ background: rgba(237, 220, 66, 0.5); + + Rows: 00002 │} + + Score: 00083 │pre.terminal { + + │ background-color: #2e3440; + + │ font-size: 0.9em; + + │ line-height: 1; + + │} + + │pre.terminal code { + + │ white-space: pre; + + │} + + │</style> + + │ + + │For [a post about org-mode kombucha]({% + + │post_url 2025-09-04-org-mode-kombucha %}) I've ++++++++++++ │been 1: 0R-*Tetris* │ 1: 0 -2025-09-05-tmux-to-html.md
Some things are missing and colors are not all perfectly rendered, but it's a good approximation and it helps a lot sharing terminal content on the web.
Credits to the following posts which contain more details: