X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fyoink;a=blobdiff_plain;f=scripts%2Fman2html.lua;fp=scripts%2Fman2html.lua;h=e33a12622d2a1663536012e195d19a6a43ee2c47;hp=0000000000000000000000000000000000000000;hb=6c9943707d4f33035830eba0587a61a34eaecbc2;hpb=af88821a172c4dfd138b91b2a5148ae50b502fa2 diff --git a/scripts/man2html.lua b/scripts/man2html.lua new file mode 100755 index 0000000..e33a126 --- /dev/null +++ b/scripts/man2html.lua @@ -0,0 +1,82 @@ +#!/usr/bin/env lua + +-- +-- Yoink +-- Run this script to convert the manual page to html. +-- + +function showhelp() + print("Usage: "..arg[0].." [-eh] [-i manpage] [-o htmlfile]") + print(" Convert the manual page to html with groff.") + print("") + print(" -e Hide email addresses in the manual page.") + print(" -h Show this help an exit.") + print(" -i Specify the manual page to convert.") + print(" -o Specify output path of html file.") +end + +----- + +function die(...) print("die:", ...); os.exit(1) end +function isReadable(file) return os.execute("test -r "..file) == 0 end + +arg.hideEmail = false +arg.output = "yoink.html" + +arg.input = "yoink.6" +if not isReadable(arg.input) then arg.input = "build/doc/yoink.6" end + +do + local t = { + ["-e"] = function(a,i) a.hideEmail = true end, + ["-h"] = function(a,i) showhelp(); os.exit() end, + ["-i"] = function(a,i) a.input = a[i+1]; return 1 end, + ["-o"] = function(a,i) a.output = a[i+1]; return 1 end + } + function parseArgs(args) + local skip = 0 + for i,v in ipairs(args) do + if skip <= 0 then + if type(t[v]) ~= "function" then + print("unknown option: "..v) + showhelp(); os.exit(1) + end + skip = t[v](args, i) + if tonumber(skip) then skip = skip + 1 else skip = 1 end + end + skip = skip - 1 + end + end +end +parseArgs(arg) + +filters = { + function(t) -- 1. Edit page title + return t:gsub("().*()", "%1Yoink Manual%2") + end, + function(t) -- 2. Insert footer before + return t:gsub("", [[ +

+ This manual page was generated on ]]..os.date("%d %b %Y")..[[. + For more information, go to the + Yoink website. +

+ ]]) + end, + arg.hideEmail and function(t) -- 3. Hide email addresses + return t:gsub("<.+@.+>", "<email address hidden>") + end or nil +} + +output, err = io.open(arg.output, "w") +if not output then die("io.open", err) end +input = io.popen("groff -t -e -mandoc -Thtml "..arg.input) + +for line in input:lines() do + for _,filter in ipairs(filters) do line = filter(line) end + output:write(line.."\n") +end + +output:close() +input:close() +