Jump to content

Module:Poetry

From Wikisource

--[[
divify

Main entry point for Lua function to wrap individual lines of poetry in passed string in protective <div>..</div> pairs.

Usage:

  {{#invoke:Poetry|divify|poetry-string}}
]]

Poetry = {};

function Poetry.divify(frame)
    rhyme = frame.args[1] or ""

    -- Noting passed in? Acceptable as response.
    if rhyme == '' then
        return rhyme
    end

    return '<div>' .. mw.ustring.gsub( rhyme, '\n', '</div>\n<div>' ).. '</div>'
end

--[[
rmuid

Main entry point for Lua function to remove any and all unit-ids (typically "em", "ex" etc.) from quantity presented and return truncated result.

Usage:

  {{#invoke:Poetry|rmuid|3em|cm|em|ex|in|mm|pc|pt|px}}

  would in this case return the string "3".
]]

function Poetry.rmuid(frame)
    local quantity = frame.args[1] or ""

    -- Iterate over remaining arguments, and remove each string found from quantity.
    key = 2
    while ( frame.args[key] ~= nil ) do
        quantity = mw.ustring.gsub( quantity, frame.args[key], '' )
        key = key + 1
    end

    return quantity
end

return Poetry