diff options
author | bptato <nincsnevem662@gmail.com> | 2024-03-21 16:35:44 +0100 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2024-03-21 16:35:44 +0100 |
commit | 71af803e1696cd87177ca3e9b16778288b75c69b (patch) | |
tree | f68346dd8a3a549e4359e0d7db16caea9bc6fa59 | |
parent | e4463ecb7c435894c5a67a3377823ab0f991a191 (diff) | |
download | chawan-71af803e1696cd87177ca3e9b16778288b75c69b.tar.gz |
ansi2html: add separate switch for "standalone"
this way its output can be embedded into documents without a pointless DT declaration
-rw-r--r-- | adapter/format/ansi2html.nim | 8 | ||||
-rwxr-xr-x | bonus/git.cgi | 2 | ||||
-rw-r--r-- | res/mailcap | 2 |
3 files changed, 9 insertions, 3 deletions
diff --git a/adapter/format/ansi2html.nim b/adapter/format/ansi2html.nim index fe8deef4..2906e076 100644 --- a/adapter/format/ansi2html.nim +++ b/adapter/format/ansi2html.nim @@ -1,4 +1,5 @@ import std/options +import std/os import std/selectors import io/posixstream @@ -357,7 +358,10 @@ proc processData(state: var State, buf: openArray[char]) = proc main() = let ps = newPosixStream(stdin.getFileHandle()) var state = State(os: newPosixStream(stdout.getFileHandle())) - state.puts("<!DOCTYPE html>\n<body><pre style='margin: 0'>") + let standalone = paramCount() >= 1 and paramStr(1) == "-s" + if standalone: + state.puts("<!DOCTYPE html>\n<body>") + state.puts("<pre style='margin: 0'>") ps.setBlocking(false) var buffer {.noinit.}: array[4096, char] var selector = newSelector[int]() @@ -373,6 +377,8 @@ proc main() = selector.registerHandle(ps.fd, {Read}, 0) discard selector.select(-1) selector.unregister(ps.fd) + if standalone: + state.puts("</body>") state.flushOutbuf() main() diff --git a/bonus/git.cgi b/bonus/git.cgi index 9038f332..5bbf12a3 100755 --- a/bonus/git.cgi +++ b/bonus/git.cgi @@ -54,7 +54,7 @@ if (params[0] == "log") { const cgi = `${query.prefix}git.cgi?prefix=${query.prefix}&path=${query.path}¶ms=show`; const titleParams = params.join(' ').replace(/[&<>]/g, x => ({'&': '&', '<': '<', '>': '>'}[x])); - console.log(`<title>git ${titleParams}</title>`); + console.log(`<!DOCTYPE html>\n<title>git ${titleParams}</title>`); while ((l = f.getline()) !== null) { console.log(l.replace(/[a-f0-9]{40}/g, x => `<a href='${cgi}%20${x}'>${x}</a>`)); diff --git a/res/mailcap b/res/mailcap index 07ac93f7..4d6619d7 100644 --- a/res/mailcap +++ b/res/mailcap @@ -3,4 +3,4 @@ text/gopher; "$CHA_LIBEXEC_DIR"/gopher2html -u "$MAILCAP_URL"; x-htmloutput text/gemini; "$CHA_LIBEXEC_DIR"/gmi2html; x-htmloutput text/markdown; "$CHA_LIBEXEC_DIR"/md2html; x-htmloutput -text/x-ansi; "$CHA_LIBEXEC_DIR"/ansi2html; x-htmloutput +text/x-ansi; "$CHA_LIBEXEC_DIR"/ansi2html -s; x-htmloutput |