local M = {} M.proto = "http" M.__fes_banner_set = false local function isHttp() -- return M.proto == "http" return false end local function isGemini() -- return M.proto == "gemini" return true end M.p = function(s) s = s or "" if isHttp() then return "

" .. s .. "

" elseif isGemini() then return s end end M.h = function(level, s) level = tonumber(level) or 1 if level < 1 then level = 1 end if level > 6 then level = 6 end s = s or "" if isHttp() then return "" .. s .. "" elseif isGemini() then return "\n" .. string.rep("#", level) .. " " .. s .. "\n" end end M.codeblock = function(s) s = s or "" if isHttp() then return "
" .. s .. "
" elseif isGemini() then return "```\n" .. s .. "\n```" end end M.inline = function(s) s = s or "" if isHttp() then return "" .. s .. "" elseif isGemini() then return "`" .. s .. "`" end end M.link = function(url, text) url = url or "" text = text or url if isHttp() then return "" .. text .. "" elseif isGemini() then return "=> " .. url .. " " .. text end end M.list = function(items, ordered) items = items or {} if isHttp() then local tag = ordered and "ol" or "ul" local out = "<" .. tag .. ">" for _, v in ipairs(items) do out = out .. "
  • " .. v .. "
  • " end out = out .. "" return out elseif isGemini() then local out = {} for i, v in ipairs(items) do if ordered then table.insert(out, i .. ". " .. v) else table.insert(out, "* " .. v) end end return table.concat(out, "\n") end end M.blockquote = function(s) s = s or "" if isHttp() then return "
    " .. s .. "
    " elseif isGemini() then return "> " .. string.gsub(s, "\n", "\n> ") end end M.rule = function() if isHttp() then return "
    " elseif isGemini() then return "---" end end M.image = function(alt, src) alt = alt or "" src = src or "" if isHttp() then return "\""" elseif isGemini() then return "=> " .. src .. " " .. alt end end M.file = function(text, url) text = text or "" url = url or "" if isHttp() then return "" .. text .. "" elseif isGemini() then return "=> " .. url .. " " .. text end end M.note = function(text) text = text or "" if isHttp() then return "
    " .. text .. "
    " elseif isGemini() then return "\n" .. text .. "\n" end end M.banner = function (text) text = text or "" if M.__fes_banner_set then error("Page already contains header") return "" end M.__fes_banner_set = true if isHttp() then return "
    " .. text .. "
    " elseif isGemini() then return text end end return M