dev

This module was made as a sandbox for the user DarthKitty. This documentation is kept to prevent redlinks.


-- <nowiki>
--------------------------------------------------------------------------------
-- Script for [[Template:Quote]].
--
-- @todo Snag CSS from Figverse Wiki.
-- @todo Consider adding multiple speakers.
-- @todo
--     Consider supporting `<poem>` tags. The manual wikitext parsing makes this
--     more difficult.
-- @todo
--     Consider adding third parameter, for parity with preexisting template on
--     dev wiki.
--------------------------------------------------------------------------------
local p = {}
local getArgs = require("Dev:Arguments").getArgs
local checkType = require("libraryUtil").checkType

--------------------------------------------------------------------------------
-- @todo
--
-- @param {string} text
--     @todo
-- @param {string} source
--     @todo
-- @returns {string}
--     @todo
--------------------------------------------------------------------------------
function p._main(text, source)
    checkType("Dev:Quote._main", 1, text, "string")
    checkType("Dev:Quote._main", 2, source, "string")

    local quote = mw.html.create("blockquote")
        :addClass("template-quote")

    -- Manually parse wikitext to improve HTML output.
    for paragraph in mw.text.gsplit(text, "\n\n") do
        quote:tag("p")
            :wikitext(paragraph)
    end

    quote:tag("cite")
        :wikitext(source)

    return tostring(quote)
end

--------------------------------------------------------------------------------
-- @todo
--
-- @param {table} frame
--     @todo
-- @returns {string}
--     @todo
--------------------------------------------------------------------------------
function p.main(frame)
    local args = getArgs(frame, {
        parentFirst = true,
    })

    return p._main(args[1], args[2])
end

--------------------------------------------------------------------------------
-- For backward compatibility.
--------------------------------------------------------------------------------
do
    local legacy = require("Module:Quote/legacy")

    for name, func in pairs(legacy) do
        if p[name] then
            error("name collision in Dev:Quote")
        end

        p[name] = func
    end
end

return p