Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.
Revision as of 05:14, 20 March 2026 by Admin (talk | contribs) (Created page with "local p = {} function p.render(frame) local args = frame:getParent().args -- Build alias map (named params that aren't positional) -- e.g. |oz=Wizard of Oz => aliases["oz"] = "Wizard of Oz" local aliases = {} for k, v in pairs(args) do if type(k) == "string" and v ~= "" then aliases[k] = mw.text.trim(v) end end -- Collect ordered positional pairs: |key|value|key|value... local lines = {} local i = 1...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Documentation for this module may be created at Module:Dialogue/doc

local p = {}

function p.render(frame)
    local args = frame:getParent().args
    
    -- Build alias map (named params that aren't positional)
    -- e.g. |oz=Wizard of Oz  => aliases["oz"] = "Wizard of Oz"
    local aliases = {}
    for k, v in pairs(args) do
        if type(k) == "string" and v ~= "" then
            aliases[k] = mw.text.trim(v)
        end
    end

    -- Collect ordered positional pairs: |key|value|key|value...
    local lines = {}
    local i = 1
    while args[i] ~= nil do
        local key = mw.text.trim(args[i])
        local val = args[i+1] and mw.text.trim(args[i+1]) or ""
        table.insert(lines, {key = key, val = val})
        i = i + 2
    end

    -- Render
    local out = {}
    for _, line in ipairs(lines) do
        local key = line.key
        local val = line.val
        if key == "action" then
            table.insert(out, string.format(
                '<div class="dialogue-action">[%s]</div>', mw.text.trim(val)
            ))
        else
            local speaker = aliases[key] or key
            table.insert(out, string.format(
                '<div class="dialogue-line"><span class="dialogue-speaker">%s</span><span class="dialogue-text">&#8220;%s&#8221;</span></div>',
                mw.text.sanitizePattern and speaker or mw.text.trim(speaker),
                val
            ))
        end
    end

    return '<div class="dialogue">' .. table.concat(out, "\n") .. '</div>'
end

return p