From bdccda5d155578f6564bd7b13f1d1affd48b0671 Mon Sep 17 00:00:00 2001 From: mitchell <70453897+667e-11@users.noreply.github.com> Date: Fri, 16 Mar 2012 16:53:53 -0400 Subject: Moved "Markdown:" comments into module LuaDoc comments. --- doc/markdowndoc.lua | 40 ++++++++++++++++++---------------------- 1 file changed, 18 insertions(+), 22 deletions(-) (limited to 'doc/markdowndoc.lua') diff --git a/doc/markdowndoc.lua b/doc/markdowndoc.lua index 6c181a7b..359c73cb 100644 --- a/doc/markdowndoc.lua +++ b/doc/markdowndoc.lua @@ -11,6 +11,7 @@ local table_concat = table.concat local M = {} local NAVFILE = '%s* [%s](%s)\n' +local FIELD = '\n### `%s` %s\n\n' local FUNCTION = '\n### `%s` (%s)\n\n' --local FUNCTION = '### `%s` (%s)\n\n' local DESCRIPTION = '%s\n\n' @@ -21,7 +22,7 @@ local RETURN = '* %s\n' local SEE = '* [`%s`](#%s)\n' local TABLE = '\n### `%s`\n\n' --local TABLE = '### `%s`\n\n' -local FIELD = '* `%s`: %s\n' +local TFIELD = '* `%s`: %s\n' local HTML = [[ @@ -170,30 +171,24 @@ function M.start(doc) -- Write the header and description. f:write('# ', name, '\n\n') f:write(module.description, '\n\n') + f:write('- - -\n\n') - -- Extract any Markdown doc comments and insert them. - -- Markdown doc comments must immediately proceed a 'module' declaration - -- (excluding blank lines), start with '-- Markdown:', and end on a blank or - -- uncommented line. - if filename then - local module_declaration, markdown = false, false - local module_file = io_open(filename, 'rb') - for line in module_file:lines() do - if not module_declaration and line:find('^module') then - module_declaration = true - elseif module_declaration and not markdown and line ~= '' then - if line ~= '-- Markdown:' then break end - markdown = true - elseif markdown then - line = line:match('^%-%-%s?(.*)$') - if not line then break end - f:write(line, '\n') + -- Write fields. + if module.doc[1].class == 'module' then + local fields = module.doc[1].field + if fields and #fields > 0 then + table.sort(fields) + f:write('## Fields\n\n') + f:write('- - -\n\n') + for _, field in ipairs(fields) do + local type, description = fields[field]:match('^(%b())%s*(.+)$') + f:write(string_format(FIELD, field, field, type or '')) + write_description(f, description or fields[field]) + f:write('- - -\n\n') end + f:write('\n') end - module_file:close() end - f:write('\n') - f:write('- - -\n\n') -- Write functions. local funcs = module.functions @@ -223,7 +218,7 @@ function M.start(doc) local tbl = tables[tname] f:write(string_format(TABLE, tbl.name, tbl.name)) write_description(f, tbl.description) - write_hashmap(f, 'Fields', FIELD, tbl.field) + write_hashmap(f, 'Fields', TFIELD, tbl.field) write_list(f, 'Usage', USAGE, tbl.usage) write_list(f, 'See also', SEE, tbl.see) f:write('- - -\n\n') @@ -238,6 +233,7 @@ function M.start(doc) template.toc, template.main = p:read('*all'):match('^(.-\n\n)(.+)$') p:close() template.toc = template.toc:gsub('()', '%1%2') -- strip params + :gsub('([^<]+)', '%1') -- sans serif f = io_open(M.options.output_dir..'/api/'..name..'.html', 'wb') local html = HTML:gsub('%%%(([^)]+)%)', template) f:write(html) -- cgit v1.2.3