]>
Dogcows Code - chaz/yoink/blob - scripts/man2html.lua
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 isReadable(file
) return os
.execute("test -r "..file
) == 0 end
24 arg
.output
= "yoink.html"
27 if not isReadable(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 skip
= skip
+ 1 else skip
= 1 end
54 function(t
) -- 1. Edit page title
55 return t
:gsub("(<title>).*(</title>)", "%1Yoink Manual%2")
57 function(t
) -- 2. Insert footer before </body>
58 return t
:gsub("</body>", [[
59 <p style="font-size: 9px; text-align: center;">
60 This manual page was generated on ]]..os
.date("%d %b %Y")..[[.
61 For more information, go to the
62 <a href="http://www.dogcows.com/yoink">Yoink website</a>.
66 arg
.hideEmail
and function(t
) -- 3. Hide email addresses
67 return t
:gsub("<.+@.+>", "<email address hidden>")
71 output
, err
= io
.open(arg
.output
, "w")
72 if not output
then die("io.open", err
) end
73 input
= io
.popen("groff -t -e -mandoc -Thtml "..arg
.input
)
75 for line
in input
:lines() do
76 for _
,filter
in ipairs(filters
) do line
= filter(line
) end
77 output
:write(line
.."\n")
This page took 0.045101 seconds and 5 git commands to generate.