diff options
Diffstat (limited to 'doc/markdowndoc.lua')
-rw-r--r-- | doc/markdowndoc.lua | 45 |
1 files changed, 31 insertions, 14 deletions
diff --git a/doc/markdowndoc.lua b/doc/markdowndoc.lua index 3dade210..a93c97c6 100644 --- a/doc/markdowndoc.lua +++ b/doc/markdowndoc.lua @@ -32,6 +32,9 @@ local HTML = [[ </head> <body> <div id="content"> + <div id="header"> + %(header) + </div> <div id="nav"> <h2>Modules</h2> %(nav) @@ -43,6 +46,9 @@ local HTML = [[ <div id="main"> %(main) </div> + <div id="footer"> + %(footer) + </div> </div> </body> </html> @@ -106,8 +112,22 @@ end -- Called by LuaDoc to process a doc object. -- @param doc The LuaDoc doc object. function M.start(doc) + local template = { + title = 'Textadept API', header = '', toc = '', main = '', footer = '' + } local modules, files = doc.modules, doc.files + -- Create the header and footer, if given a template. + local header, footer = '', '' + if M.options.template_dir ~= 'luadoc/doclet/html/' then + local p = io.popen('markdown "'..M.options.template_dir..'header.md"') + template.header = p:read('*all') + p:close() + p = io.popen('markdown "'..M.options.template_dir..'footer.md"') + template.footer = p:read('*all') + p:close() + end + -- Create the navigation list. local hierarchy = {} for _, name in ipairs(modules) do @@ -125,9 +145,15 @@ function M.start(doc) write_nav(f, hierarchy) f:close() local p = io_popen('markdown "'..navfile..'"') - local nav = p:read('*all') + template.nav = p:read('*all') p:close() + -- Write index.html. + f = io_open(M.options.output_dir..'/api/index.html', 'wb') + local html = HTML:gsub('%%%(([^)]+)%)', template) + f:write(html) + f:close() + -- Create a map of doc objects to file names so their Markdown doc comments -- can be extracted. local filedocs = {} @@ -207,25 +233,16 @@ function M.start(doc) f:close() -- Write HTML. + template.title = name..' - Textadept API' local p = io_popen('markdown -f toc -T "'..mdfile..'"') - local toc, main = p:read('*all'):match('^(.-\n</ul>\n)(.+)$') + template.toc, template.main = p:read('*all'):match('^(.-\n</ul>\n)(.+)$') p:close() - toc = toc:gsub('(<a.-)%b()(</a>)', '%1%2') -- strip function parameters + template.toc = template.toc:gsub('(<a.-)%b()(</a>)', '%1%2') -- strip params f = io_open(M.options.output_dir..'/api/'..name..'.html', 'wb') - local html = HTML:gsub('%%%(([^)]+)%)', { - title = name..' - Textadept API', nav = nav, toc = toc, main = main - }) + local html = HTML:gsub('%%%(([^)]+)%)', template) f:write(html) f:close() end - - -- Write index.html. - f = io_open(M.options.output_dir..'/api/index.html', 'wb') - local html = HTML:gsub('%%%(([^)]+)%)', { - title = 'Textadept API', nav = nav, toc = '', main = '' - }) - f:write(html) - f:close() end return M |