Last active
August 5, 2021 12:34
-
-
Save lesslol/55e42d00595fe45ff2e2 to your computer and use it in GitHub Desktop.
Create lua 5.3 chm manual
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- | |
-- Create Lua53.chm | |
-- | |
-- Directory Structure | |
-- | |
-- C:\Program Files (x86)\HTML Help Workshop\hhc.exe | |
-- doc\manual.html, etcs. | |
-- README | |
-- luachm.lua | |
-- htmlhelp compiler | |
local hhc = [["C:\Program Files (x86)\HTML Help Workshop\hhc.exe"]] | |
-- check hhc | |
local function exists(p) | |
local f; if p:find('^"') then f = io.open(p:sub(2,#p-1)) else f = io.open(p) end | |
if f then f:close(); return true else return false end | |
end | |
assert(exists(hhc),'not found hhc.exe') | |
-- check lrex | |
local r, rex = pcall(require, 'rex_onig') | |
if not r then r, rex = pcall(require, 'rex_pcre') end | |
if not r then r, rex = pcall(require, 'rex_posix') end | |
if not r then r, rex = pcall(require, 'rex_gnu') end | |
assert(r,'not found lrex') | |
-- check doc path | |
local f = io.open('doc/contents.html'); assert(f,'not found doc/contents.html') | |
-- start | |
local o = io.open("lua53.hhp", "w+") | |
o:write([[ | |
[OPTIONS] | |
Title=Lua 5.3 Manual | |
Contents file=contents.hhc | |
Display compile progress=1 | |
Default topic=doc/readme.html# | |
#Index file=index.hhk | |
#Full-text search=1 | |
[FILES] | |
README | |
]]) | |
o:close() | |
local c = io.open('contents.hhc', 'w+') | |
c:write([[<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> | |
<HTML><BODY> | |
<UL> | |
<LI><OBJECT type="text/sitemap"> | |
<param name="Name" value="Welcome to Lua 5.3"> | |
<param name="Local" value="doc/readme.html"> | |
<param name="ImageNumber" value="11"> | |
</OBJECT> | |
<LI><OBJECT type="text/sitemap"> | |
<param name="Name" value="Contents"> | |
<param name="Local" value="doc/contents.html"> | |
<param name="ImageNumber" value="11"> | |
</OBJECT> | |
<LI><OBJECT type="text/sitemap"> | |
<param name="Name" value="Index"> | |
<param name="Local" value="doc/contents.html#index"> | |
<param name="ImageNumber" value="11"> | |
</OBJECT> | |
]]) -- contents | |
local k = io.open('index.hhk', 'w+') | |
k:write([[<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> | |
<HTML><BODY> | |
<UL> | |
]]) -- indexes | |
local tabs = 1 | |
local ptab = 1 | |
r = f:read('*l') | |
while r do | |
local href, lvl, _, name = rex.match(r, [[<A HREF="([^""]+)">([0-9\.]*) (–| )([^<]+)</A>]]) | |
if href and name then | |
local padding = tabs + rex.count(lvl, '\\.') | |
if ptab < padding then | |
c:write(string.rep('\t', ptab)) | |
c:write('<UL>\n') | |
ptab = padding | |
elseif ptab > padding then | |
c:write(string.rep('\t', padding)) | |
c:write('</UL>\n') | |
ptab = padding | |
end | |
c:write(string.rep('\t', padding)) | |
c:write('<LI><OBJECT type="text/sitemap">\n'); c:write(string.rep('\t', padding)) | |
c:write(' <param name="Name" value="'..name..'">\n'); c:write(string.rep('\t', padding)) | |
c:write(' <param name="Local" value="doc/'..href..'">\n'); c:write(string.rep('\t', padding)) | |
c:write(' </OBJECT>\n') | |
-- write index | |
k:write('<LI><OBJECT type="text/sitemap">\n') | |
k:write(' <param name="Name" value="'..name..'">\n') | |
k:write(' <param name="Local" value="doc/'..href..'">\n') | |
k:write(' </OBJECT>\n') | |
else | |
href, name = rex.match(r, [[<A HREF="([^""]+)">([^ <0-9][^<]+)</A>]]) | |
if href and name then | |
k:write('<LI><OBJECT type="text/sitemap">\n') | |
k:write(' <param name="Name" value="'..name..'">\n') | |
k:write(' <param name="Local" value="doc/'..href..'">\n') | |
k:write(' </OBJECT>\n') | |
end | |
end | |
r = f:read('*l') | |
end | |
f:close() | |
c:write([[ | |
<LI><OBJECT type="text/sitemap"> | |
<param name="Name" value="Changes since Lua 5.2"> | |
<param name="Local" value="doc/readme.html#changes"> | |
<param name="ImageNumber" value="11"> | |
</OBJECT> | |
<LI><OBJECT type="text/sitemap"> | |
<param name="Name" value="License"> | |
<param name="Local" value="doc/readme.html#license"> | |
<param name="ImageNumber" value="11"> | |
</OBJECT> | |
<LI><OBJECT type="text/sitemap"> | |
<param name="Name" value="README"> | |
<param name="Local" value="README"> | |
<param name="ImageNumber" value="11"> | |
</OBJECT> | |
</UL> | |
</BODY></HTML>]]);c:close() | |
k:write('</UL>\n</BODY></HTML>');k:close() | |
os.execute(hhc..' lua53.hhp') | |
os.execute('del *.hhp *.hhc *.hhk') | |
os.execute('lua53.chm') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment