From 6391a9a2abde4e6a681cb0a1a1831d0c1b87026a Mon Sep 17 00:00:00 2001 From: bptato Date: Fri, 15 Mar 2024 12:18:45 +0100 Subject: man: improve header/footer conversion * run processBackspace on the first line, because groff likes to print formatting there too * check man references like SAMEPAGE(1) with isCommand because it's commonly found in footers --- adapter/protocol/man.nim | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'adapter/protocol/man.nim') diff --git a/adapter/protocol/man.nim b/adapter/protocol/man.nim index 17f44dea..f8aa6ad8 100644 --- a/adapter/protocol/man.nim +++ b/adapter/protocol/man.nim @@ -98,7 +98,7 @@ iterator myCaptures(captures: var seq[RegexCapture]; target: int; cap.e += offset yield cap -proc processManpage(file: File; header: string) = +proc processManpage(file: File; header, keyword: string) = var line: string # The "right thing" would be to check for the error code and output error # messages accordingly. Unfortunately that would prevent us from streaming @@ -123,7 +123,7 @@ proc processManpage(file: File; header: string) = # this is useful because otherwise the header would get caught in the man # regex, and that makes navigation slightly more annoying stdout.write(header) - stdout.write(line & '\n') + stdout.write(line.processBackspace() & '\n') var wasBlank = false template re(s: static string): Regex = let r = s.compileRegex({LRE_FLAG_GLOBAL, LRE_FLAG_UTF16}) @@ -138,6 +138,9 @@ proc processManpage(file: File; header: string) = let includeRe = re"#include(|\s)*<([\w./-]+)" let manRe = re"()*(\w[\w.-]*)()*(\([0-9nlx]\w*\))" var paths: seq[string] = @[] + var ignoreMan = keyword.toUpperAscii() + if ignoreMan == keyword or keyword.len == 1: + ignoreMan = "" for p in getEnv("PATH").split(':'): var i = p.high while i > 0 and p[i] == '/': @@ -212,6 +215,10 @@ proc processManpage(file: File; header: string) = secCap.s += offset secCap.e += offset let man = line[manCap.s.." & man & "" line[manCap.s..man """ & manword & """ -
""")
+
""", keyword = keyword)
 
 proc doLocal(man, path: string) =
   # Note: we intentionally do not use -l, because it is not supported on
@@ -247,7 +254,7 @@ proc doLocal(man, path: string) =
   file.processManpage(header = """Content-Type: text/html
 
 man -l """ & path & """
-
""")
+
""", keyword = path.afterLast('/').until('.'))
 
 proc doKeyword(man, keyword, section: string) =
   let sectionOpt = if section == "": "" else: " -s " & section
-- 
cgit 1.4.1-2-gfad0