local M = {} M.proto = "http" local function isHttp() return M.proto == "http" end local function isGemini() return M.proto == "gemini" end local function esc(s) s = s or "" s = s:gsub("&", "&") s = s:gsub("<", "<") s = s:gsub(">", ">") return s end M.p = function(s) s = s or "" if isHttp() then return "

" .. esc(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 "" .. esc(s) .. "" elseif isGemini() then return string.rep("#", level) .. " " .. s end end M.codeblock = function(s) s = s or "" if isHttp() then return "
" .. esc(s) .. "
" elseif isGemini() then return "```\n" .. s .. "\n```" end end M.inline = function(s) s = s or "" if isHttp() then return "" .. esc(s) .. "" elseif isGemini() then return "`" .. s .. "`" end end M.link = function(text, url) text = text or "" url = url or "" if isHttp() then return "" .. esc(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 .. "
  • " .. esc(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 "
    " .. esc(s) .. "
    " elseif isGemini() then return "> " .. s 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 "" .. esc(text) .. "" elseif isGemini() then return "=> " .. url .. " " .. text end end return M