add note back into the standard library

This commit is contained in:
2026-02-16 21:43:05 -05:00
parent 472e27b1fa
commit f8287de023
2 changed files with 55 additions and 0 deletions

View File

@@ -127,4 +127,57 @@ M.file = function(text, url)
end
end
M.note = function(text)
text = text or ""
if isHttp() then
return "<div class=\"note\">" .. esc(text) .. "</div>"
elseif isGemini() then
local width = 31
local function wrap_line(line)
local out = {}
local i = 1
local len = #line
if len == 0 then
out[#out + 1] = ""
return out
end
while i <= len do
out[#out + 1] = line:sub(i, i + width - 1)
i = i + width
end
return out
end
local lines = {}
for line in (text .. "\n"):gmatch("(.-)\n") do
local wrapped = wrap_line(line)
for _, w in ipairs(wrapped) do
lines[#lines + 1] = w
end
end
local border = "+" .. string.rep("=", width + 2) .. "+"
local empty = "|" .. string.rep(" ", width + 2) .. "|"
local out = {}
out[#out + 1] = border
out[#out + 1] = empty
for _, line in ipairs(lines) do
local padding = width - #line
out[#out + 1] = "| " .. line .. string.rep(" ", padding) .. " |"
end
out[#out + 1] = empty
out[#out + 1] = border
return table.concat(out, "\n")
end
end
return M