add note back into the standard library
This commit is contained in:
53
lib/std.lua
53
lib/std.lua
@@ -127,4 +127,57 @@ M.file = function(text, url)
|
|||||||
end
|
end
|
||||||
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
|
return M
|
||||||
|
|||||||
@@ -5,4 +5,6 @@ local site = fes.fes("gemini")
|
|||||||
|
|
||||||
site:h(1, "Hello, World!")
|
site:h(1, "Hello, World!")
|
||||||
|
|
||||||
|
site:note("Hello, World!. djsaklllllll\nlllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll")
|
||||||
|
|
||||||
return site
|
return site
|
||||||
|
|||||||
Reference in New Issue
Block a user