Module:Poem: Difference between revisions
Jump to navigation
Jump to search
HyperNervie (talk | contribs) (Workaround alternative for Extension:Poem) |
(No difference)
|
Revision as of 05:55, 5 September 2025
Documentation for this module may be created at Module:Poem/doc
local p = {}
function p.makePoem(text)
local poem = mw.html.create("div"):addClass("poem"):tag("p")
if text == "" then return tostring(poem:done()) end
if mw.ustring.sub(text, -1) ~= "\n" then text = text .. "\n" end
local pos, len = 1, mw.ustring.len(text)
while pos <= len do
local _, e, colons, line = mw.ustring.find(text, "(:*)(.-)\n", pos)
local indent = mw.ustring.len(colons)
if indent > 0 then
poem:tag("span")
:css("display", "inline-block")
:css("margin-inline-start", indent .. "em")
:wikitext(line)
else poem:wikitext(line) end
if e ~= len then poem:wikitext("<br>") end
pos = e + 1
end
return tostring(poem:done())
end
function p.main(frame)
local text = frame:getParent().args.content or frame:getParent().args[1]
or frame.args.content or frame.args[1] or ""
return p.makePoem(text)
end
return p