aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519>2019-12-07 19:34:33 -1000
committercel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519>2019-12-07 19:34:33 -1000
commit02044cb4be75b9a46439f79179efc828aceb7d50 (patch)
treec2151323b529553767a9ef2cb561fd5109a81f0d
parent4e26a3c71dac45ed4a0d0f5d92d82e34526120ed (diff)
Use ansi2html if possible
-rw-r--r--README.md2
-rwxr-xr-xgemini.filter.dpi12
2 files changed, 11 insertions, 3 deletions
diff --git a/README.md b/README.md
index 3f19563..f1f611c 100644
--- a/README.md
+++ b/README.md
@@ -10,6 +10,8 @@
dillo-gemini requires the `openssl` command-line tool.
+[ansi2html](https://pypi.org/project/ansi2html/) is optionally required to render pages that use ANSI escape codes (e.g. for colors).
+
This repo is hosted on the [SSB Network][SSB] using [git-ssb][].
```sh
diff --git a/gemini.filter.dpi b/gemini.filter.dpi
index 3400c45..c9e17d1 100755
--- a/gemini.filter.dpi
+++ b/gemini.filter.dpi
@@ -22,9 +22,15 @@ serve_404() {
}
render_gemini() {
- printf "Content-type: text/html\r\n\r\n<!doctype html><pre>"
- sed 's/^\(=>\s*\)\(\S*\)*\(.*\)/\1<a href="\2">\2<\/a>\3/'
- printf "%s" "</pre>"
+ printf "Content-type: text/html\r\n\r\n"
+ if which ansi2html 2>&1 >/dev/null
+ then
+ ansi2html | sed 's/^\(=&gt;\s*\)\(\S*\)*\(.*\)/\1<a href="\2">\2<\/a>\3/'
+ else
+ printf "<!doctype html><pre>"
+ sed 's/^\(=>\s*\)\(\S*\)*\(.*\)/\1<a href="\2">\2<\/a>\3/'
+ printf "%s" "</pre>"
+ fi
}
send_status_msg() {