From 75a5bdedbe3299b4a8d58239fd6d4ddaf52c8e5b Mon Sep 17 00:00:00 2001 From: bptato Date: Fri, 29 Mar 2024 16:32:04 +0100 Subject: ansi2html: support passing titles Use content type attributes so e.g. git.cgi can set the title even with a text/x-ansi content type. (This commit also fixes some bugs in content type attribute handling.) --- adapter/format/ansi2html.nim | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) (limited to 'adapter/format/ansi2html.nim') diff --git a/adapter/format/ansi2html.nim b/adapter/format/ansi2html.nim index 4266a3ba..9abc6925 100644 --- a/adapter/format/ansi2html.nim +++ b/adapter/format/ansi2html.nim @@ -356,11 +356,39 @@ proc processData(state: var State, buf: openArray[char]) = of '\0': state.puts("\uFFFD") # HTML eats NUL, so replace it here else: state.putc(c) +proc usage() = + stderr.write("Usage: ansihtml [-s] [-t title]\n") + quit(1) + proc main() = var state = State() - let standalone = paramCount() >= 1 and paramStr(1) == "-s" + # parse args + let H = paramCount() + var i = 1 + var standalone = false + var title = "" + while i <= H: + let s = paramStr(i) + if s == "": + inc i + if s[0] != '-': + usage() + for j in 1 ..< s.len: + case s[j] + of 's': + standalone = true + of 't': + inc i + if i > H: usage() + title = paramStr(i).percentDecode() + else: discard + inc i + if standalone: + state.puts("\n") + if title != "": + state.puts("" & title.htmlEscape() & "\n") if standalone: - state.puts("\n") + state.puts("\n") state.puts("
\n")
   let ofl = fcntl(STDIN_FILENO, F_GETFL, 0)
   doAssert ofl != -1
-- 
cgit 1.4.1-2-gfad0