Jump to content

Module:RemoveMiddleColumn

From Untitled Monster Game
Revision as of 14:53, 30 December 2025 by imported>Ziebster
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Example Usage:

{{Device Disambiguation|Example}}

local p = {}

function p.slim(frame)
    local text = frame.args[1] or ""
    if text == "" then return "" end
    local lines = {}
    for line in text:gmatch("([^\n]*)\n?") do
        table.insert(lines, line)
    end
    local result = {}
    local i = 1
    while i <= #lines do
        local trimmed = lines[i]:match("^%s*(.-)%s*$") or ""
        if trimmed:match("^<section") or trimmed:match("^</section") then
            table.insert(result, lines[i])
        elseif trimmed:match("^%{%|") then
            table.insert(result, lines[i])
        elseif trimmed:match("^|%}") then
            table.insert(result, lines[i])
        elseif trimmed:match("^|%-") then
            table.insert(result, lines[i])
        elseif trimmed:match("^!") then
            local headers = {}
            while i <= #lines and lines[i]:match("^%s*!") do
                table.insert(headers, lines[i])
                i = i + 1
            end
            i = i - 1
            if #headers == 3 then
                table.insert(result, headers[1])
                table.insert(result, headers[3])
            end
        elseif trimmed:match("^|") and not trimmed:match("^|%-") and not trimmed:match("^|%}") then
            local cells = {}
            while i <= #lines and lines[i]:match("^%s*|") and not lines[i]:match("^%s*|%-") and not lines[i]:match("^%s*|%}") do
                table.insert(cells, lines[i])
                i = i + 1
            end
            i = i - 1
            if #cells == 3 then
                table.insert(result, cells[1])
                table.insert(result, cells[3])
            end
        else
            table.insert(result, lines[i])
        end
        i = i + 1
    end
    return table.concat(result, "\n")
end

return p