From 02044cb4be75b9a46439f79179efc828aceb7d50 Mon Sep 17 00:00:00 2001 From: cel Date: Sat, 7 Dec 2019 19:34:33 -1000 Subject: Use ansi2html if possible --- README.md | 2 ++ gemini.filter.dpi | 12 +++++++++--- 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
"
-	sed 's/^\(=>\s*\)\(\S*\)*\(.*\)/\1\2<\/a>\3/'
-	printf "%s" "
" + printf "Content-type: text/html\r\n\r\n" + if which ansi2html 2>&1 >/dev/null + then + ansi2html | sed 's/^\(=>\s*\)\(\S*\)*\(.*\)/\1\2<\/a>\3/' + else + printf "
"
+		sed 's/^\(=>\s*\)\(\S*\)*\(.*\)/\1\2<\/a>\3/'
+		printf "%s" "
" + fi } send_status_msg() { -- cgit v1.2.3