]>
Dogcows Code - chaz/yoink/blob - man2html.lua
c7663c5f976d7fe25f07d3ad85c3447e0784b304
5 -- Run this script to convert the manual page to html.
9 print("Usage: "..arg
[0].." [-eh] [-i manpage] [-o htmlfile]")
10 print(" Convert the manual page to html with groff.")
12 print(" -e Hide email addresses in the manual page.")
13 print(" -h Show this help an exit.")
14 print(" -i Specify the manual page to convert.")
15 print(" -o Specify output path of html file.")
20 function die(...) print("die:", ...); os
.exit(1) end
21 function readable(file
) return os
.execute("test -r "..file
) == 0 end
24 arg
.output
= "yoink.html"
27 if not readable(arg
.input
) then arg
.input
= "build/doc/yoink.6" end
31 ["-e"] = function(a
,i
) a
.hideEmail
= true end,
32 ["-h"] = function(a
,i
) showhelp(); os
.exit() end,
33 ["-i"] = function(a
,i
) a
.input
= a
[i
+1]; return 1 end,
34 ["-o"] = function(a
,i
) a
.output
= a
[i
+1]; return 1 end
36 function parseArgs(args
)
38 for i
,v
in ipairs(args
) do
40 if type(t
[v
]) ~= "function" then
41 print("unknown option: "..v
)
42 showhelp(); os
.exit(1)
45 if tonumber(skip
) then
58 function(t
) -- 1. Edit page title
59 return t
:gsub("(<title>).*(</title>)", "%1Yoink Manual%2")
61 function(t
) -- 2. Insert footer before </body>
62 return t
:gsub("</body>", [[
63 <p style="font-size: 9px; text-align: center;">
64 This manual page was generated on ]]..os
.date("%d %b %Y")..[[.
65 For more information, go to the
66 <a href="http://www.dogcows.com/yoink">Yoink website</a>.
70 arg
.hideEmail
and function(t
) -- 3. Hide email addresses
71 return t
:gsub("<.+@.+>", "<email address hidden>")
75 output
, err
= io
.open(arg
.output
, "w")
76 if not output
then die("io.open", err
) end
77 input
= io
.popen("groff -t -e -mandoc -Thtml "..arg
.input
)
79 for line
in input
:lines() do
80 for _
,filter
in ipairs(filters
) do line
= filter(line
) end
81 output
:write(line
.."\n")
This page took 0.034932 seconds and 3 git commands to generate.