summaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
Diffstat (limited to 'doc')
-rw-r--r--doc/doc.lua100
-rw-r--r--doc/ftr.html3
-rw-r--r--doc/hdr.html55
3 files changed, 158 insertions, 0 deletions
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 @@
+ </body>
+
+</html>
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 @@
+<!doctype html>
+
+<html>
+
+<head>
+ <meta name="viewport" content="width=device-width initial-scale=1 maximum-scale=1 minimum-scale=1 user-scalable=0" />
+ <title>CGI for Caddy</title>
+ <style>
+ body {
+ max-width: 800px;
+ font-family: sans-serif;
+ padding: 1em;
+ }
+
+ h1,
+ h2,
+ h3 {
+ color: #345;
+ }
+
+ .syntax {
+ display: block;
+ white-space: pre;
+ font-family: monospace;
+ background-color: #efe;
+ border: 1px solid #474;
+ margin: 1em 0;
+ padding: 0.25em 1.5em;
+ }
+
+ .warning {
+ background-color: #ffd;
+ border: 1px solid #665;
+ margin: 1em 0;
+ padding: 0.25em 1.5em;
+ }
+
+ .key {
+ color: #474;
+ }
+
+ .subkey {
+ font-style: italic;
+ }
+
+ pre {
+ margin: 1.5em 0;
+ background-color: #eee;
+ padding: 1em;
+ overflow-x: scroll;
+ }
+ </style>
+</head>
+
+<body>