From 88c06828a097914c971a893f0048cd911e9b1a22 Mon Sep 17 00:00:00 2001 From: Kurt Date: Tue, 30 Apr 2019 14:32:56 -0400 Subject: Use Lua script to generate README, doc.go and index.html rather than autoreadme --- doc/doc.lua | 100 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ doc/ftr.html | 3 ++ doc/hdr.html | 55 ++++++++++++++++++++++++++++++++ 3 files changed, 158 insertions(+) create mode 100644 doc/doc.lua create mode 100644 doc/ftr.html create mode 100644 doc/hdr.html (limited to 'doc') diff --git a/doc/doc.lua b/doc/doc.lua new file mode 100644 index 0000000..dbe87c1 --- /dev/null +++ b/doc/doc.lua @@ -0,0 +1,100 @@ +-- This script reads a single page of Markdown-like documentation and generates +-- output in three different forms: gofmt, git-flavored markdown, and +-- standard markdown. + +local gsub, match, len, find, concat, insert = +string.gsub, string.match, string.len, string.find, table.concat, table.insert + +local function write(filestr, str) + local f = io.open(filestr, 'w+') + if f then + f:write(str) + f:close() + end +end + +local function codeblock(tbl, mode) + local newtbl = {} + local incode = false + local pos1, pos2, prefix, syntax + for j, str in ipairs(tbl) do + prefix, syntax = match(str, '^(```)(%a*)') + if prefix and len(syntax) > 0 then + incode = true + if mode == 'r' then + insert(newtbl, str) + end + elseif prefix then + incode = false + if mode == 'r' then + insert(newtbl, str) + end + else + if incode and mode ~= 'r' then + str = '\t' .. str + end + insert(newtbl, str) + end + end + return newtbl +end + +local function markdownwrite(tbl, filestr) + tbl = codeblock(tbl, 'm') + local str = concat(tbl, '\n') + write(filestr, str) +end + +local function readmewrite(tbl, filestr) + tbl = codeblock(tbl, 'r') + local str = concat(tbl, '\n') + str = gsub(str, '\n%> ', '\n') + -- str = gsub(str, '%b<>', '') + write(filestr, str) +end + +local function godocwrite(tbl, filestr) + tbl = codeblock(tbl, 'g') + for j, str in ipairs(tbl) do + str = gsub(str, '^#+ *', '') + tbl[j] = gsub(str, '^* ', '\n• ') + end + local str = concat(tbl, '\n') + str = gsub(str, '\n\n\n+', '\n\n') + str = gsub(str, '\n%> ', '\n') + str = gsub(str, '`', '') + str = gsub(str, '/%*', '\x01') + str = gsub(str, '%*', '') + str = gsub(str, '\x01', '\x2f*') + -- str = gsub(str, '%b<>', '') + -- replace [foo][bar] with foo + str = gsub(str, '%[(%C-)%]%[%C-%]', '%1') + str = '/*\n' .. str .. '\n*/\npackage gofpdf\n' + write(filestr, str) +end + +local godoc, markdown, readme = {}, {}, {} +local modeg, modem, moder + +for str in io.lines('document.md') do + local mode = string.match(str, '^~(%a*)~$') + if mode then + modeg = find(mode, 'g') ~= nil + moder = find(mode, 'r') ~= nil + modem = find(mode, 'm') ~= nil + else + if modeg then + insert(godoc, str) + end + if modem then + insert(markdown, str) + end + if moder then + insert(readme, str) + end + end +end + +markdownwrite(markdown, 'doc/body.md') +godocwrite(godoc, 'doc.go') +readmewrite(readme, 'README.md') diff --git a/doc/ftr.html b/doc/ftr.html new file mode 100644 index 0000000..47fc456 --- /dev/null +++ b/doc/ftr.html @@ -0,0 +1,3 @@ + + + diff --git a/doc/hdr.html b/doc/hdr.html new file mode 100644 index 0000000..bbc2758 --- /dev/null +++ b/doc/hdr.html @@ -0,0 +1,55 @@ + + + + + + + CGI for Caddy + + + + -- cgit v1.2.1-24-ge1ad