[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: table of contents for lua50, final
- From: "Gordon A. Acocella" <gaa@...>
- Date: Wed, 16 Apr 2003 00:00:57 -0400
No problem if you don't have perl (I couldn't resist):
#!/usr/bin/env lua
-- lua50doc.lua, directly translated from:
-- lua50toc.pl -- Joe Myers, joe31416@procrasticon.com 04/15/03
-- globals
Infi = 'manual.html' -- input file
Outfi = 'manual2.html' -- revised manual w/ 'ref:---' tags
Tocfi = 'manual2-toc.html' -- new table of contents
-- Second arg is unused (gsub passes all captures).
function process(wholematch, _, mrk, tag)
local name = 'ref:' .. tag
TOCFI:write('<a href="', Outfi, '#', name, '">', mrk, '</a><br>\n')
return '<a name="' .. name .. '">' .. wholematch
end
OUTFI = io.open(Outfi, 'w')
TOCFI = io.open(Tocfi, 'w')
TOCFI:write[[
<html>
<head>
<title>lua50 contents (04/2003)</title>
</head>
<body>
<H1><center>lua50 contents (04/2003)</center></H1>
]]
IN = io.open(Infi, 'r')
_ = IN:read('*a') -- slurp!
IN:close()
-- Perl's regular expressions are more powerful than lua's.
-- I had to simplify this a little (it's not exactly the same):
_ = string.gsub(_, '(<([hH][1-3])>((%d[%d%.]*)%s-%s.-)</%2>)', process)
OUTFI:write(_)
OUTFI:close()
TOCFI:write('</body></html>\n')
TOCFI:close()
-- This could be skipped for systems without wc.
os.execute('wc -l ' .. Tocfi .. ' ' .. Outfi)
Joe Myers wrote:
>
> Hello List,
>
> I missed a table of contents for the new (nice!) lua50 final distro, so I
> wrote a perlscript to create one (appended below). So I'm sending this on
> in case anyone else would find it useful.
>
> Simply run this in the same directory as manual.html, it will create
> files manual2.html and manual2-toc.html (table of contents).
>
> If you've trouble running it (like, if you don't have perl installed), let
> me know, I can either put this on the wiki / my website / or email you the
> resulting files (too large to send on a list).
>
> Joe